-
-
Notifications
You must be signed in to change notification settings - Fork 689
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
Cannot increase height with certain pdf files (sample included) #399
Comments
Hello @mugli! In the example you shared the page height is being set by the following line: page.setHeight(height + headerHeight); This method abstracts away a lot of annoying little PDF details and works well for most documents. However, the abstraction does break for certain documents, like the one you shared. The PDF spec defines 5 different boxes that control the positioning and clipping of content on a page ( Lines 159 to 166 in 3c15aa5
The Instead of calling the const mediaBox = page.node.MediaBox();
const cropBox = page.node.CropBox();
const newMediaBox = mediaBox.clone();
newMediaBox.set(3, doc.context.obj(height + headerHeight));
page.node.set(PDFName.of('MediaBox'), newMediaBox);
if (cropBox) {
const newCropBox = cropBox.clone();
newCropBox.set(3, doc.context.obj(height + headerHeight));
page.node.set(PDFName.of('CropBox'), newCropBox);
} This results in the page height being successfully updated for both documents that you shared. I hope this is helpful. Please let me know if you have any additional questions! |
I would like for the |
Thank you so much. This does fix my problem for now. I'm going with the sample code you provided here. If I find any more pdf files not working with this, I'll refer to this issue again with new samples. You can close it for now if you want. Have a nice day! |
I'm trying to increase the height of a page to add "header" to pdf files using pdf-lib. The code works for most of the files but also doesn't work with certain files. It's not clear why it doesn't work, there is no error. This looks like a bug in the library, but I could be wrong.
I have added a demo repository for demonstrating this with both working and not-working samples here: https://github.com/mugli/demo-adding-header-to-pdf
Please let me know if there's a better way to achieve this or if there's any workaround.
The text was updated successfully, but these errors were encountered: