Skip to content
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

PDF Form Field Flattening #12

Closed
lkeyes opened this issue Aug 10, 2020 · 7 comments
Closed

PDF Form Field Flattening #12

lkeyes opened this issue Aug 10, 2020 · 7 comments

Comments

@lkeyes
Copy link

lkeyes commented Aug 10, 2020

Hi...I'm attempting to craft a Powershell solution which merges a series of existing PDF Forms, which "flattens" the forms prior to adding them to the merged PDF. I want the original data displayed that was put into the form, but I don't care that the form functionality is lost. I was hoping this might be available in PSWritePDF. -- Thanks!

@PrzemyslawKlys
Copy link
Member

What happens if you try to merge them?

@lkeyes
Copy link
Author

lkeyes commented Aug 11, 2020 via email

@markdem
Copy link
Contributor

markdem commented May 19, 2021

Can I please revive this request? I also need to be able to flatten the PDF.
I am too much of a sissy to fix this issue myself and not too sure how to use github anyway, but the fix would be simply;

  1. add a ps optional parameter to Set-PDFform, somthing like -flatten
  2. if the pram is true, just run this line "$PDFAcroForm.flattenFields();"

Have a look at https://kb.itextpdf.com/home/it7kb/examples/flattening-a-form.

Thanks, and great work.

@markdem
Copy link
Contributor

markdem commented May 19, 2021

I have just tested this, and it works fine. I cant work out how to change it here. Any chance someone else can do it (or tell me how)?

2 things need to be changed;

  1. add "[bool] $Flatten" to the param list of "Set-PDFForm"
  2. add " if($Flatten) {$PDFAcroForm.flattenFields()}" just before "$PDF.Close()" at the end.

I have tested with the param set to true, false and null. all works as expected

@PrzemyslawKlys
Copy link
Member

The "online" way to do it is simply edit the file in GitHub.

image

When you do that, a new fork is created and you get your own version of code. Then you can keep editing until you're happy. And then you get an option to create PR.

My recommendations:

  1. Make it a switch
  2. Make it possible to support setting up the form and then at the end if it user chooses Set-PDFForm -FlattenForm it would make it flat

But also make it possible that if no FIeldNameAndValueHashtable is provided - it still works as expected just flattening the form.

It would be interesting to "improve" Merge-PDF with [switch] $FlattenForms or similar so that if there is a form detected it would flatten it during merge if requested.

@markdem
Copy link
Contributor

markdem commented May 19, 2021

Cool, learned something new today. Thanks!
Good point with the switch too. Not sure why I did not think of that.
Suggestion 2 already works that way. If no hash table is provided, the foreach will do nothing, still check the $Flatten switch and flatten empty. Tested this too.

If I get some spare time in the next few days, I will have a look at Merge-PDF. Should be doable.

PrzemyslawKlys added a commit that referenced this issue May 23, 2021
@PrzemyslawKlys
Copy link
Member

This is now live. Thank you @markdem - I've improved the cmdlet a bit and added a test for flattening. I really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants