Would it be possible to add an option to grab width and height from an image and _then_ doc.addPage(x: 0, y:0, width: myImageWidth, height: myImageHeight) ?
PDFKit already reads image size and it would save some complexity (adding image-size dependency)
My use case is adding several compressed scanned JPEGs to a PDF. I'd venture to say auto-sizing the pages is an expected convenience.
You can achieve this with the openImage function added in v0.8.1:
var doc = new PDFDocument({autoFirstPage:false});
var img = doc.openImage(image_path_or_buffer);
doc.addPage({size: [img.width, img.height]});
doc.image(img, 0, 0);
Thanks for the tip! Unfortunately it's an SVG and openImage throws 'Unknown image format'.
SVG images are not directly supported in PDFKit.
There are many packages to convert them to JPEG or PNG.
You can also use SVG-to-PDFKit but it doesn't give the image size beforehand (I plan to change this in the future)
Not available for Typescript. Any idea when it will be?
Most helpful comment
You can achieve this with the
openImagefunction added in v0.8.1: