Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blobStream is not defined #13

Closed
sagarvibrant opened this issue Oct 20, 2019 · 8 comments
Closed

blobStream is not defined #13

sagarvibrant opened this issue Oct 20, 2019 · 8 comments

Comments

@sagarvibrant
Copy link

sagarvibrant commented Oct 20, 2019

I'm Using in Angular 8, When i call
var ctx = new canvas2pdf.Context(blobStream());
its throw - blobStream is not defined

@joshua-gould
Copy link
Owner

joshua-gould commented Oct 21, 2019 via email

@sagarvibrant
Copy link
Author

sagarvibrant commented Oct 22, 2019

In new canvas2pdf.PdfContext (blobStream() I passed Only one Parameter but there in canvas2pdf.js there were two parameters
canvas2pdf.PdfContext = function (stream, options) {
if (stream == null) {
throw new Error('Stream must be provided.');
}
var _this = this;
var doc = new PDFDocument(options);
this.stream = doc.pipe(stream);
this.doc = doc;

I dont understand what data passed in options parameter .

my code -
var pdfCanvas: any = document.querySelector('canvas');
var ctx = new canvas2pdf.PdfContext(window.blobStream());
ctx.fillStyle = 'yellow';
ctx.fillRect(100, 100, 100, 100);
pdfCanvas.src = ctx.stream.toBlobURL('application/pdf');

Its throw error
PDFDocument is not defined
i think its throw because of options parameter is undifined

Thank you.

@sagarvibrant sagarvibrant reopened this Oct 22, 2019
@joshua-gould
Copy link
Owner

joshua-gould commented Oct 22, 2019 via email

@sagarvibrant
Copy link
Author

Thanks @joshua-gould its removes my error,
Generated Url -- blob:http://localhost:4200/fa0ef7a8-3c65-479b-b0a4-53e605a06083
but PDF is not open .
blobPDF

var pdfCanvas: any = document.querySelector('canvas');
var blobStream = window.blobStream();
var ctx = new canvas2pdf.PdfContext(window.blobStream(), pdfCanvas);
console.log(ctx);
var blob = ctx.stream.toBlobURL('application/pdf');
console.log(blob);
window.open(blob, 'example.pdf', true);

I use fabric js canvas.

@joshua-gould
Copy link
Owner

You have to issue drawing commands after creating an instance of canvas2pdf.PdfContext.

@sagarvibrant
Copy link
Author

@joshua-gould Can you please give me plunker or stackblitz demo.

@joshua-gould
Copy link
Owner

joshua-gould commented Oct 23, 2019 via email

@sagarvibrant
Copy link
Author

canvas2pdf_fabricdata
This is canvas data what I get.
How can I use canvas2pdf with fabric js canvas ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants