Open marcusy3k opened 6 years ago
There is a separate package for this - google svg pdfkit On Thu, 12 Jul 2018 at 22:21, Marcus notifications@github.com wrote:
Possible to add SVG image embedding? really hope it is supported because we want to include barcode(s) in pdf file, Normally, barcode is generated as SVG image by external function at runtime (e.g. JsBarcode -- https://github.com/lindell/JsBarcode ).
I need to use SVG because vector image is much better for barcode images to avoid blur images or too low resolutions, it is bad for printing.
Any suggestion is appreciated.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/devongovett/pdfkit/issues/844, or mute the thread https://github.com/notifications/unsubscribe-auth/AAlGtUIg_WmKzTsugaS0cad5Fn6A8iD0ks5uFyMygaJpZM4VMlqn .
Thanks, I think I do not understand SVG things... JsBarcode could write to HTML as:
<img id="bcimg" src="data:image/png;base64,......">
or
<svg id="barcode" width="288px" height="59px" x="0px" y="0px" viewBox="0 0 288 59" xmlns="http://www.w3.org/2000/svg" version="1.1" style="transform: translate(0,0)"><rect x="0" y="0" width="288" height="59" style="fill:#ffffff;"></rect><g transform="translate(10, 5)" style="fill:#000000;"><rect x="0" y="0" width="4" height="30"></rect><rect x="6" y="0" width="2" height="30"></rect> ... <text style="font: 12px monospace" text-anchor="middle" x="134" y="44">AAA1234567890</text></g></svg>
The barcode could be shown on web page, but how could I add it to PDF ?
Why don't you just use a barcode font?
Except Code39, other barcode fonts (such as code128) could not be really used directly, if using it alone, the printed barcode could not be read by barcode reader. As far as I know, the code128 font file usually need extra program to convert the text in order to generate a readable barcode...
But yes, using barcode font is a good way too.
You can use the png image directly in pdfkit:
doc.image('data:image/png;base64,...', 0, 0, {})
or the svg with https://github.com/alafr/SVG-to-PDFKit:
SVGtoPDF(doc, '<svg id="barcode" ... </svg>', 0, 0, {});
Resolution should not be an issue in png if barcode lines are a multiple of entire pixels.
Thanks, alafr
@alafr and @blikblum would it be possible to directly integrate SVG into PDFKit? It would be awesome if we could gather all possible PDF features into a unique library! This library is the most complete javascript library for PDF (AFAIK)...
Possible to add SVG image embedding? really hope it is supported because we want to include barcode(s) in pdf file, Normally, barcode is generated as SVG image by external function at runtime (e.g. JsBarcode -- https://github.com/lindell/JsBarcode ).
I need to use SVG because vector image is much better for barcode images to avoid blur images or too low resolutions, it is bad for printing.
Any suggestion is appreciated.