Setting Font Attributes While Replacing Text
You can specify font attributes like Font Color, Font Size, Font Family and Font Style using Aspose.Pdf.Kit for Java. We have introduced TextProperties class for that purpose, which is enclosed in PdfContentEditor class. You need to create an object of this class, with required attributes, and pass it to the replaceText method.
Using this class, you can set Font Style like Italic or Bold, Font Size and Font Color. You can also set the Font Family; however currently Aspose.Pdf.Kit for Java can only support the following 14 standard type 1 fonts: Times-Roman, Helvetica, Courier, Symbol, Times-Bold, Helvetica-Bold, Courier-Bold, ZapfDingbats, Times-Italic, Helvetica-Oblique, Courier-Oblique, Times-BoldItalic, Helvetica-BoldOblique, Courier-BoldOblique
The following example shows you how to apply font attributes while replacing text:
You can specify font attributes like Font Color, Font Size, Font Family and Font Style using Aspose.Pdf.Kit for Java. We have introduced TextProperties class for that purpose, which is enclosed in PdfContentEditor class. You need to create an object of this class, with required attributes, and pass it to the replaceText method.
Using this class, you can set Font Style like Italic or Bold, Font Size and Font Color. You can also set the Font Family; however currently Aspose.Pdf.Kit for Java can only support the following 14 standard type 1 fonts: Times-Roman, Helvetica, Courier, Symbol, Times-Bold, Helvetica-Bold, Courier-Bold, ZapfDingbats, Times-Italic, Helvetica-Oblique, Courier-Oblique, Times-BoldItalic, Helvetica-BoldOblique, Courier-BoldOblique
The following example shows you how to apply font attributes while replacing text:
//create PdfContentEditor object PdfContentEditor editor = new PdfContentEditor(); //crete TextProperties object with Font Style, Bold and Italic attributes PdfContentEditor.TextProperties textProperties = new PdfContentEditor.TextProperties("Courier", true, true); //set font size textProperties.setTextSize(20); //set font color textProperties.setColor(java.awt.Color.red); //bind input PDF file editor.bindPdf("input.pdf"); //replace text with text properties editor.replaceText("Source String", "Destination String", textProperties); //save the output file editor.save("output.pdf"); editor.close();
