Hi,
I am trying to set the font for TextFragment which I need to write in to existing pdf file. Applied font is not reflected in the final pdf.
Please find the attached image to see the difference, I applied the same font which is applied in the left side of the document(highlighted with 1) and for Confidential label written using the TextFragment as below code snippet.
if(defaultFontStr != null){
defaultFont = com.aspose.pdf.FontRepository.findFont(defaultFontStr);
}
TextFragment designation =
new TextFragment(“Confidential”);
designation.getTextState().setFontSize(fontSize);
if(defaultFont != null){
designation.getTextState().setFont(defaultFont);
}
while finding the font i dont see any error aswell.
Please help me in this regard.
Thanks,
Shivaji
Hi Shivaji,
Please find attached zip file which contains, source pdf and font(.ttf) file.
Hi Shivaji,
com.aspose.pdf.Document doc = new
com.aspose.pdf.Document(“C:\pdftest\source_pdf_font\Shivaji.Dole_1454441557021.pdf”); <o:p></o:p>
com.aspose.pdf.Font defaultFont = com.aspose.pdf.FontRepository.findFont("Times New Roman");
TextFragment designation = new TextFragment("Confidential");
designation.getTextState().setFontSize(12);
if(defaultFont != null)
{
designation.getTextState().setFont(defaultFont);
}
designation.getMargin().setTop(100);
designation.getMargin().setLeft(20);
doc.getPages().get_Item(1).getParagraphs().add(designation);
designation.getTextState().setForegroundColor(com.aspose.pdf.Color.getRed());
doc.save("C:\\pdftest\\source_pdf_font\\Shivaji.Dole_1454441557021_Updated.pdf");
Hi,
Thank you for the update.
We are using aspose-pdf-10.2.0.jar for writing the text to pdf.
JDK1.7 we are using.
Operating system we used is linux, where our servers are running.
When i run it locally, i can see this fonts are applied properly, but in linux machine, its different.
Please verify on linux machines and let me know.
Thanks.
Shivaji
Can you please update me on this.
Hi Shivaji,
Hi Shivaji,
Thanks for your patience.
I have tested the scenario using latest release of Aspose.Pdf for Java 11.2.0 on Non-Windows platform using JDK 1.8.0_60 and I am unable to notice any issue while adding text in Times New Roman font. Can you please try using the latest release and in case the issue still persists, please share the version of Linux which you are using, so that we can further look into this matter.
For your reference, I have also attached the output generated over my end.
[Java]
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(“Shivaji.Dole_1454441557021.pdf”);
com.aspose.pdf.Font defaultFont = com.aspose.pdf.FontRepository.findFont(“Times New Roman”);
TextFragment designation = new TextFragment(“Confidential”);
designation.getTextState().setFontSize(12);
if(defaultFont != null)
{
designation.getTextState().setFont(defaultFont);
}
designation.getMargin().setTop(100);
designation.getMargin().setLeft(20);
doc.getPages().get_Item(1).getParagraphs().add(designation);
designation.getTextState().setForegroundColor(com.aspose.pdf.Color.getRed());
doc.save(“Shivaji.Dole_1454441557021_Updated.pdf”);