Copy link to clipboard
Copied
I use multiple tools in Acrobat which generate text box "stamps" onto one or pages of a PDF document when certain conditions are met. These tools are mostly functional, however I am struggling to apply the correct formatting to the text boxes. Certain properties such as text and fill color function correctly, however despite my attempts to code font and size properties into these auto-generated boxes, they will always ignore the coded properties and instead revert to the default font settings.
In this code, for example, none of the text properties are able to overwrite the default document settings. I have other tools which help me to retroactively apply standard color and text size rules to the entire document to address the color issue, however I still have to manually change the font. I would like to be able to have all the correct properties appear as soon as the box is generated:
var stampSample = this.addAnnot({
page: 0,
type: "FreeText",
rect: [250, 25, 560, 100],
contents: "sample text",
fillColor: color.white,
strokeColor: color.white,
textColor: color.black,
textSize: 10,
textFont: "Times-Roman",
readonly: false
I've tried variations on the formatting of the text font name (font.Times, "Times Roman", etc.) with no success. I've had success with color formatting by modifying the richContents of boxes after they are created, however I haven't found a solution to apply that method here.
You have to do it by creating rich contents objects like this:
var stampSample = this.addAnnot({
page: 0,
type: "FreeText",
rect: [250, 25, 560, 100],
fillColor: color.white,
strokeColor: color.white,
readonly: false
});
var spans=[];
spans[0]={};
spans[0].textColor=color.black;
spans[0].textSize=10;
spans[0].text="SAMPLE TEXT";
spans[0].textFont="Times-Roman";
stampSample.richContents=spans;
Copy link to clipboard
Copied
You have to do it by creating rich contents objects like this:
var stampSample = this.addAnnot({
page: 0,
type: "FreeText",
rect: [250, 25, 560, 100],
fillColor: color.white,
strokeColor: color.white,
readonly: false
});
var spans=[];
spans[0]={};
spans[0].textColor=color.black;
spans[0].textSize=10;
spans[0].text="SAMPLE TEXT";
spans[0].textFont="Times-Roman";
stampSample.richContents=spans;
Copy link to clipboard
Copied
Thanks! That fixed all but the Font Style, which still reverts back to the document default rather than updating to the Times Roman.
Copy link to clipboard
Copied
I tested it before I posted it. Did you remove the annotation and copy the script before running it?
Copy link to clipboard
Copied
I did. I'm testing if the new text boxes reflect the desired changes by changing the default text size, font, and color for text boxes before executing the code. The size and color are corrected to the desired properties, but the font is not.