pdf - .net, Itextsharp, how to flatten comments (specifically stamps)? -


in short, i'm having issues "flattening" stamp comments in pdf's while using itextsharp. effect i'm looking identical when "print pdf" acrobat (the stamp can no longer moved/edited/etc. can still select text might have). using simple javascript code seems work fine (this.flattenpages).

this problems seems pertain stamps, real trick of it. i've used pdfstamper class flatten other kinds of page comments , annotations (e.g. text boxes) using:

   stamper.formflattening = true     stamper.freetextflattening = true 

but not work stamps i've tried (the default included in acrobat or user created). document comes out on other end same editable stamp. so... ideas? , please let me know if there's additional information can provide. thanks.

update: not same other annotations. whatever it's worth, stamps (specifically) show overcontents. how 1 go changing flag or otherwise merging/flattening onto page else can't find documentation for.

thanks mkl's comment (see above) pointing me in right direction, i've found solution. here's abridged explanation of fix:

i downloaded , edited source code itextsharp , re-compiled .dll small changes needed. there's other routes this, turned out simplest , elegant solution. requires including few additional or statements present code. note there's reason isn't included in official library, buyer beware:

in pdfstamperimp class, there's few small edits required make flatten stamps , behave wanted to. changes made flatfreetextfields procedure:

if (!(anndic.get(pdfname.subtype)). equals(pdfname.freetext))                      continue; } 

changes to:

if (!(anndic.get(pdfname.subtype)).equals(pdfname.freetext) | (anndic.get(pdfname.subtype)).equals(pdfname.stamp)) {                     continue; } 

and

if (pdfname.freetext.equals(annot.get(pdfname.subtype))) {             annots.remove(idx);             --idx; } 

changes to:

if (pdfname.freetext.equals(annot.get(pdfname.subtype)) | pdfname.stamp.equals(annot.get(pdfname.subtype))) {            annots.remove(idx);            idx -= 1; } 

as can see, it's not complex change in world. here, call stamper.freetextflatten = true normal , work stamps well. theoretically rid of these statements altogether , (at least attempt) annotations on page. suspect might not safe idea, can't sure.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -