These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Flatten Text Field boxes but not comments or stamps

EOPE
Registered: Feb 9 2011
Posts: 6
Answered

Does anyone know of a js to flatten the text boxes, but not the comments or stamps in acrobat?
Basically, I have a pdf that has many text fields that I add client's information. Then I want to flatten the text fields so not to change the text field or even notice the text field boxes. However, I have comments for instructions/explanation in comments and sign here stamps. I then email client the pdf. I want client to be able to see the doc with the comments and stamp, but not print the comments and sign here stamp on the final document.
 
thanks

My Product Information:
Acrobat Pro 9.4, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Accepted Answer
When you use the doc.flattenPages JavaScript method, you can specify the nNonPrint parameter to specify which annotations you want to flatten. Specifically, you can exclude non-printing annotations from getting flattened. This means that your script can loop through the collection of annotations, store the current print property for each, set it to false, and set all of the fields to print (display = visible), then flatten the pages. You'd then restore the print property of each annotation to it's original state.
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
It's possible, but you need to hack a bit. The only function available to JS that flattens annotations is the flattenPages() method of the doc object. Although very few people use all three, it has the following parameters:

doc.flattenPages(nStart, nEnd, nNonPrint)

nStart and nEnd are the page range to flatten, with the first page in the file being page 0.

Setting nNonPrint=1 causes the method to ignore any annotations which are set as "do not print", whatever their subtype, so if you run a script which first scans through all your annotations and sets the annotation's ".print" parameter to boolean false or boolean true as required, run the flattenPages() command, then reset the printability back to true, you can in effect set a user-defined filter on the flattening operation.

Here's an example that flattens everything EXCEPT stamps:

this.syncAnnotScan();
var annots = this.getAnnots();
for (var i = 0; i < annots.length; i++) {
annots[i].print = (annots[i].type!="Stamp");
}
flattenPages(0,numPages-1,1);
this.syncAnnotScan();
annots = this.getAnnots();
for (var i = 0; i < annots.length; i++) {
annots[i].print = true;
}
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
ahhh.. GMTA!
EOPE
Registered: Feb 9 2011
Posts: 6
Thank you Both!
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
UVSAR wrote:
ahhh.. GMTA!
But some include code to prove their crazy ideas! :)
EOPE
Registered: Feb 9 2011
Posts: 6
George_Johnson wrote:
UVSAR wrote:
ahhh.. GMTA!
But some include code to prove their crazy ideas! :)
Exactly! that is true for your response and for my original request! lol.. it is amazing how much i struggled with trying to give the response to correct answer between the both of you especially since the reason for your response being just minutes after Mr. Johnsons was due to the extra code! The code is great though, thank you both again!
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
EOPE wrote:
Does anyone know of a js to flatten the text boxes, but not the comments or stamps in acrobat?
Quite A Box Of Tricks is plugin that can do it (even in demo mode) : http://quite.com/box/index.htm

;-)


UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
I decided it's about time for a free tool that handles all this selective flattening stuff in forms and comments.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
UVSAR wrote:
I decided it's about time for a free tool that handles all this selective flattening stuff in forms and comments.
Very nice!
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
That is a good one! How long did it take you to hand-code that dialog?

Thanks for sharing :)

Dimitri
www.pdfscripting.com
www.windjack.com
UVSAR
Expert
Registered: Oct 29 2008
Posts: 1357
Dimitri wrote:
That is a good one! How long did it take you to hand-code that dialog?
Not long actually - it's the chewed up offspring of a script I did for someone to filter markups in AutoCAD drawings, so most of the dialog was already there. The painful bit is handling threaded replies properly, as if you kill a parent comment Acrobat gets really antsy about what do do with the orphans. If you think of anything to add, drop me a PM.

I'll eventually sort out a way to avoid flattening RMAs, but that's going to end up being a plugin as the SDK doesn't assign them a print attribute. Ahh, so near and yet so far...

EOPE
Registered: Feb 9 2011
Posts: 6
WOW! That widget is great!! I just saw what you created and feel like you just created the "easy button" in those tv ads!... EXCELLENT WIDGET!!