Skip to main content
Known Participant
December 28, 2022
Question

SDK C++ - burn in annotations?

  • December 28, 2022
  • 2 replies
  • 725 views

Is there a way I can burn in annotations so the onscreen images become images in the document?

It would be preferable if it were annotation by annotation.

This topic has been closed for replies.

2 replies

bebarth
Community Expert
Community Expert
December 30, 2022

Hi,

You can select an annotation then run this script from the console window or from an action wizard:

var selectedAnnot=this.selectedAnnots;
if (!selectedAnnot) app.alert("No annots selected!",3)
else if (selectedAnnot.length>1) app.alert("Please select only one annot.",3)
else {
	var annots=this.getAnnots();
	var theAnnots=[];
	for (var i=0; i<annots.length; i++) {
		if (annots[i].name!=selectedAnnot[0].name) {
			theAnnots.push(annots[i].print);
			annots[i].setProps({print: false});
		} else annots[i].setProps({print: true});
	}
	var theFields=[];
	for (var i=0; i<this.numFields; i++) {
		theFields.push([this.getNthFieldName(i),this.getField(this.getNthFieldName(i)).display]);
		this.getField(this.getNthFieldName(i)).display=display.noPrint;
	}
	this.flattenPages({nNonPrint: 1});
	var annots=this.getAnnots();
	for (var i=0; i<annots.length; i++) annots[i].setProps({print: theAnnots[i]});
	for (var i=0; i<theFields.length; i++) {
		this.getField(theFields[i][0]).display=theFields[i][1];
	}
}

@+

Legend
December 28, 2022

In Acrobat this is called "flattening". Unfortunately people use "flattening" to mean 4 different unrelated things! But there is a JavaScript method to flatten pages, which takes the meaning you want, but for the whole of pages or file. In the plug-in API you can call JavaScript. Otherwise, the process of converting appearance streams to form XObjects and adding Do calls from the page contents is not actually impossible, but has no convenient API and requires deep PDF internals knowledge.

Known Participant
December 28, 2022

Thanks.

"In the plug-in API you can call JavaScript"
is there an example or an API to do this?

Legend
December 28, 2022

The method is AFExecuteThisScript. You just pass the script as a string.