We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose-pdf-java (19.12) font issue

Hi,
I am using licensed version of aspose pdf (19.12). Is there aspose pdf required all the fonts available in the system?

  1. I have tried to extract a fonts from the source pdf file, and try to embedded in the replacing pdf, its not working.Its make an error: Font embedding is prohibited because of font license restrictions.
  2. Lots pdf make an error like this “font is not avialble”

Is there any other option available to replace a raw text? We need to replace lakhs pdf files.

Implemented code:

// Initialize License Instance
com.aspose.pdf.License license = new com.aspose.pdf.License();
// Call setLicense method to set license
license.setLicense(ReplaceTextAspose.class.getResourceAsStream("/Aspose.Total.Java.lic"));
final FileInputStream fis = new FileInputStream(filePath);
Document pdfDocument = new Document(fis);
textFragmentAbsorber = new TextFragmentAbsorber(“Test”, new TextSearchOptions(true));
pdfDocument.getPages().accept(textFragmentAbsorber);

// Get the extracted text fragments into collection
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
pdfDocument.getPages().accept(textFragmentAbsorber);
// Get the extracted text fragments into collection
for (TextFragment textFragment : (Iterable) textFragmentCollection) {
Font font = textFragment.getTextState().getFont();
//font.setEmbedded(true);
float font_size = textFragment.getTextState().getFontSize();
int font_weight = textFragment.getTextState().getFontStyle();
String fontName = font.getFontName();
//String required_font = (available_font_list.contains(fontName))? fontName : “”;
//if(required_font.trim() != “”) {
try {
textFragment.getTextState().setFont(FontRepository.findFont(fontName,1));
textFragment.getTextState().setFontSize(font_size);
textFragment.getTextState().setFontStyle(font_weight);
}catch(Exception e) {
String error_msg = fontName +" :"+e.getMessage();
return baseObject.handleException(error_msg);
}
}
textFragment.setText(replacement);
text_changes_done = true;
}

Thanks.

@Amaran,

Thanks for contacting support.

Can you please share source file with us so that we may further investigate to help you out.