Removal / Cropping of margins on pdf documents | Node / Javascript

Viewed 263

Trying to tackle the scenario where a PDF is a given input. The PDF has a page margin around its content and when this input PDF is compiled in to another document, which has its own resulting margins, the final appearance is off because now the content within the PDF has a "double margin", making the input pdf content smaller.

The goal is to remove margins in an input pdf BEFORE including it in the process that spits out a final document.

I have looked into node modules such as pdf-lib as to hopefully be able to crop a pdf correctly, but when most of the documents that come through seem to have all the same values for its mediabox, artbox, bleedbox, cropbox, etc... it doesn't really give us a jumping off point on how to correctly recrop this pdf. Since all the values of the previous boxes are (0,0, width of document, height of document), there is not much to go with to find where the content is starting

The hope is to do this all server side with out the need for a user to manually fix the issue.

Has anyone tried to tackle this sort of process? Thoughts? Breakdown the pdf ( which could contain almost anything ) with something like pdf2json module and create a new document with pdf-lib ?

0 Answers
Related