Repository navigation
Browser-only PDF jobs with pdf-lib: 4x6 label crop that keeps barcodes vector, real redaction, 2-up card sheets #1796
emma-walton
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi! I make fbuff.com, a set of free tools that run entirely in the browser, and pdf-lib does the PDF writing for most of them. Sharing three patterns that worked well, in case they help someone.
1. Crop a shipping label to 4x6 and keep the barcode vector
Carriers hand out a Letter page with the label in one corner. Instead of rasterizing,
embedPagetakes a bounding box, so only the label is copied and the barcode stays sharp at any printer resolution:Remember to add the crop box origin (
view.x,view.y): some carrier PDFs don't start at 0,0. Pages that have their own/Rotatewere easier to handle as a 300 DPI raster fallback.2. Redaction that really removes the text
Drawing black rectangles over a PDF leaves the text underneath selectable. The redactor renders each page with PDF.js at 200 DPI, burns the boxes into the canvas, and builds a new document from the JPEGs, with
PDFDocument.create({ updateMetadata: false })so no producer, creator or dates are written and nothing is copied from the original file.3. Two 4x6 cards on one Letter sheet
For printable cards, one
embedPngand twodrawImagecalls on a landscape 792x612 page, plus shortdrawLinecrop marks just outside each corner so the cut follows the card edge without printing on it.pdf-lib is loaded with a dynamic
import("pdf-lib")only when the user clicks download, which keeps it out of the first page load.The tools, if you want to see them in action: Shipping Label to 4x6, PDF Redactor, Save the Date Maker. Thanks for the library, it made all of this possible without a server.
All reactions