-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from joshua-gould/setTransform
added setTransform.js and test
- Loading branch information
Showing
32 changed files
with
51,323 additions
and
1,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
# Canvas2PDF | ||
# Canvas2PDF | ||
|
||
Canvas2PDF exports your HTML canvas as PDF using JavaScript. | ||
Note that this library generates actual PDF drawing calls to create a PDF with vector graphics, | ||
Canvas2PDF exports your HTML canvas as PDF using JavaScript. | ||
Note that this library generates actual PDF drawing calls to create a PDF with vector graphics, | ||
unlike some alternate libraries which rasterize your canvas and place it as an image in your PDF. | ||
|
||
|
||
## Usage | ||
|
||
```javascript | ||
import PdfContext from '/src/canvas2pdf'; | ||
import blobStream from 'blob-stream'; | ||
import { saveAs } from 'file-saver'; | ||
import PdfContext from "/src/canvas2pdf"; | ||
import blobStream from "blob-stream"; | ||
import { saveAs } from "file-saver"; | ||
|
||
// Create a new PDF canvas context. | ||
const ctx = new PdfContext(blobStream()); | ||
|
||
// draw your canvas like you would normally | ||
ctx.fillStyle = 'yellow'; | ||
ctx.fillRect(100,100,100,100); | ||
ctx.fillStyle = "yellow"; | ||
ctx.fillRect(100, 100, 100, 100); | ||
// more canvas drawing, etc... | ||
|
||
// convert your PDF to a Blob and save to file | ||
ctx.stream.on('finish', function () { | ||
var blob = ctx.stream.toBlob('application/pdf'); | ||
saveAs(blob, 'example.pdf', true); | ||
ctx.stream.on("finish", function () { | ||
const blob = ctx.stream.toBlob("application/pdf"); | ||
saveAs(blob, "example.pdf", true); | ||
}); | ||
ctx.end(); | ||
``` | ||
|
||
## Interactive Browser Demo | ||
[Open Demo](https://joshua-gould.github.io/canvas2pdf/dist/index.html) | ||
|
||
[Open Demo](https://joshua-gould.github.io/canvas2pdf/dist/index.html) | ||
|
||
## Notes | ||
+ Calling fill and then stroke consecutively only executes fill | ||
+ Some canvas 2d context methods are not implemented yet (e.g. setTransform and arcTo) | ||
|
||
- Calling fill and then stroke consecutively only executes fill | ||
- Some canvas 2d context methods are not implemented yet (e.g. arcTo) | ||
|
||
## License | ||
|
||
MIT | ||
|
||
# Developer Dependencies | ||
+ GraphicsMagick is required for running tests | ||
|
||
- GraphicsMagick is required for running tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import PdfContext from '/src/canvas2pdf'; | ||
import blobStream from 'blob-stream'; | ||
import PdfContext from "/src/canvas2pdf"; | ||
import blobStream from "blob-stream"; | ||
|
||
const editor = document.getElementById('editor_source'); | ||
const editor = document.getElementById("editor_source"); | ||
|
||
const examplePicker = document.getElementById('example_picker'); | ||
examplePicker.onchange = function() { | ||
const examplePicker = document.getElementById("example_picker"); | ||
examplePicker.onchange = function () { | ||
editor.textContent = document.getElementById(examplePicker.value).textContent; | ||
createPdf(); | ||
}; | ||
|
||
const iframe = document.querySelector('iframe'); | ||
const createPdf = function() { | ||
const iframe = document.querySelector("iframe"); | ||
const createPdf = function () { | ||
const text = editor.textContent; | ||
|
||
const stream = blobStream(); | ||
const ctx = new PdfContext(stream); | ||
|
||
ctx.stream.on('finish', function() { | ||
iframe.src = ctx.stream.toBlobURL('application/pdf'); | ||
ctx.stream.on("finish", function () { | ||
iframe.src = ctx.stream.toBlobURL("application/pdf"); | ||
}); | ||
eval(text); | ||
}; | ||
; | ||
document.getElementById('redraw').addEventListener( | ||
'click', | ||
function() { | ||
document.getElementById("redraw").addEventListener( | ||
"click", | ||
function () { | ||
createPdf(); | ||
}, | ||
false | ||
false, | ||
); | ||
|
||
createPdf(); |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.