Skip to main content
Known Participant
Dec 28, 2022 3:15 PM UTC
Question

SDK C++ - burn in annotations?

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

bebarth
Community Expert
Community Expert
Dec 30, 2022 8:33 AM UTC

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];
	}
}

@+

Translate
Legend
Dec 28, 2022 6:01 PM UTC

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.

Translate
Known Participant
Dec 28, 2022 6:08 PM UTC

Thanks.

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

Translate
Legend
Dec 28, 2022 7:39 PM UTC

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

Translate