Free Support Forum - aspose.com

Ability to add text in specific font (ZapfChancery-Roman)

We are implementing online certificates and require the font of the student’s name to be in a specific font, ZapfChancery-Roman. I am unable to find a way to specify that font when adding it to the pdf document using the following code. If there is a way to use Fill Form Fields and Flatten the PDF with this font embeded, that would be even better.

Thanks, Adam

//specify input and output PDF file paths
String inputFile = “C:\BlankDiploma.pdf”;
String outputFile = “C:\Certificate.pdf”;

//specify image file path
String imageName = “C:\paul-signature.gif”;

//create file streams for all of the files to be used in the example
FileInputStream inPdfStream = new FileInputStream(inputFile);
FileInputStream inImgStream = new FileInputStream(imageName);
FileOutputStream outputStream = new FileOutputStream(outputFile);

//create instance of PdfFileMend class
PdfFileMend mendor = new PdfFileMend(inPdfStream, outputStream);

//add image to the input PDF file on page number 1 at specified location
mendor.addImage(inImgStream, 1, 50, 50, 100, 100);

//create new FormattedText type object to add text in the PDF file
FormattedText ft = new FormattedText(“PdfFileMend testing! 0 rotation.”, new FontColor(0,0,0));


//add text in the existing PDF file
mendor.addText(ft, 1, 50, 100, 100, 200);

//claose the PdfFileMend type object
mendor.close();
//close output file stream
outputStream.close();

I have resolved the issue and it is now working properly. Here is the code incase anyone is interested. Note, you must have the specific path to the pfm. You also need to include the pfb in that very same folder.


Thanks, Adam

//specify input and output PDF file paths
String inputFile = “C:\BlankDiploma.pdf”;
String outputFile = “C:\Certificate.pdf”;

//specify image file path
String imageName = “C:\paul-signature.gif”;

//create file streams for all of the files to be used in the example
FileInputStream inPdfStream = new FileInputStream(inputFile);
FileInputStream inImgStream = new FileInputStream(imageName);
FileOutputStream outputStream = new FileOutputStream(outputFile);

//create instance of PdfFileMend class
PdfFileMend mendor = new PdfFileMend(inPdfStream, outputStream);

//add image to the input PDF file on page number 1 at specified location
mendor.addImage(inImgStream, 1, 50, 50, 100, 100);

//create new FormattedText type object to add text in the PDF file
FormattedText ft = new FormattedText(“Billy Magin Jones”, new FontColor(0, 0, 0), “c:\zcr_____.pfm”, EncodingType.Winansi, true, 30);
//add text in the existing PDF file
//addText(FormattedTexttext, intpageNum, floatlowerLeftX, floatlowerLeftY, floatupperRightX, floatupperRightY)
mendor.addText(ft, 1, 50, 400, 800, 800);

//close the PdfFileMend type object
mendor.close();

//close output file stream
outputStream.close();

Hi Adam,


Thanks for using our products and sorry for the delayed response.

When using FormattedText object to create a text string in specific font (other than system fonts), you need to specify the path to the font file. You may also specify the path to True Type font as third argument to FormattedText constructor.

FormattedText ft = new
FormattedText(“Billy
Magin Jones”
, new FontColor(0, 0, 0), “c:/pdftest/RAGE.TTF”,
EncodingType.Winansi, true, 40);<o:p></o:p>


In order to use the predefined system fonts, you may try using any value from com.aspose.pdf.kit.FontStyle enumeration and pass this value as third argument to FormattedText object constructor. In the event of any further query, please feel free to contact.