-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
[Feature Request] API to Flatten PDF Forms #554
Comments
Same problem. Any update ? |
I wound up moving away from PDF forms entirely because of this and other issues. Instead, I'm using the form field coordinates and placing my text directly on the PDF, bypassing the acroFields entirely. |
+1 on this one. I would add that flattening would allow to merge pdfs with fields having same name but different value, which is currently not possible using pdf-lib. |
Hello @mattboutet @BNovikov! pdf-lib does not currently have any APIs for flattening forms. However, such an API could certainly be build. It should be relatively easy to create (at least compared to other APIs that have been requested). I personally do not have time to work on it right now. But if anybody is interested in working on a PR for this, I'd be happy to answer questions and help get you started! |
Hi @Hopding - I would like to have a go at this feature. Can you please give me some pointers to get started :) |
i ended up using node-pdftk to fill and flatten the file at the same time. Just fyi maybe u can take a look at their code. |
Hello @VivekRajagopal! Flattening a PDF form just means flattening each field in a PDF's form. pdf-lib already has APIs to get a list of all fields in a form. To flatten an individual form field, you need to first ensure that it has an appearance stream. Most software (including pdf-lib) used to fill form fields generate appearance streams. However, pdf-lib does have APIs to generate appearance streams for filled fields that do not already have them. Once you've verified the form field has an appearance stream, you need to take the FormXObject containing the appearance stream and draw it at the end of the page's content stream. pdf-lib has APIs to get the FormXObject of an appearance stream and APIs to draw a FormXObject on a page's content stream. Be sure that you draw the FormXObject in the correct location on the page's content stream with the correct rotation. There are a number of libraries written in other languages that you can use as reference implementations of form flattening. I would recommend looking at I hope this helps! Please let me know if you have any additional questions. |
FYI @BNovikov: @Hopding already gave a wonderful answer here (#151 (comment)) that offers an alternative approach to why you're seeking to flatten -- renaming the fields from copied/merged pages :) |
@patcon , thank you, very much appreciated. I must admit I am still trying to understand the magic of this. But in my case I am trying to put static text instead of the field (would have been very easy if pdf-lib could delete fields), not to have different values in same ids, so that approach would not work. |
I haven't been able to find any way to flatten a PDF form, and I'm integrating with an API (Lob) that can't / won't handle non-flattened forms (it won't render the content of any acroFields). I've tried making the fields read-only, and I've set NeedAppearances to
true
but that doesn't cut it for this one use-case.Is there a way, even if complicated/hacky to flatten a PDF form with
pdf-lib
?The text was updated successfully, but these errors were encountered: