Hi, I am running the evaluation version of Aspose Java PDF on AWS Lambda.
Font Arial was not found: com.aspose.pdf.exceptions.FontNotFoundException
class com.aspose.pdf.exceptions.FontNotFoundException: Font Arial was not found
com.aspose.pdf.FontRepository.findFont(Unknown Source)
com.aspose.pdf.SignatureField.m1(Unknown Source)
com.aspose.pdf.SignatureField.sign(Unknown Source)
com.aspose.pdf.facades.PdfFileSignature.m1(Unknown Source)
com.aspose.pdf.facades.PdfFileSignature.save(Unknown Source)
aspose.intelleigen.com.IWFAsposePDF.handleRequest(IWFAsposePDF.java:50)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
at com.aspose.pdf.FontRepository.findFont(Unknown Source)
at com.aspose.pdf.SignatureField.m1(Unknown Source)
at com.aspose.pdf.SignatureField.sign(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.m1(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.save(Unknown Source)
at aspose.intelleigen.com.IWFAsposePDF.handleRequest(IWFAsposePDF.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
EDIT:
I found this… https://docs.aspose.com/display/pdfjava/use+pdf+core+fonts
How do I change the font used for signatures from Ariel to Helvetica?
@ngzhongcai,
Please visit this link to change font Replace fonts in existing PDF file.
Please feel free to let us know whenever you require any further assistance.
Hi Naeem,
Solution provided replace font for the entire file.
I only face this issue when adding a digital signature.
How do I add “Arial” font to the FontRepository?
@ngzhongcai,
Please use below code to change font
try
{
originalFont = FontRepository.findFont("Ariel");
}
catch (com.aspose.pdf.exceptions.FontNotFoundException e)
{
FontRepository.getSubstitutions().add(new SimpleFontSubstitution("Ariel", "Helvetica"));
}
Am sorry to bother with repeated questions…
I tried setting the FontRepository.getSu…add… method right at the top…
FontRepository.getSubstitutions().add(new SimpleFontSubstitution("Ariel", "Helvetica"));
Font font= FontRepository.findFont("Ariel");
The second line caused the same exception.
I thought the first line would have set the font in place.
I also tried uploading a TFF font resource together with the JAR file. And then adding it to the FontRepository by using the “document.setLocalFontPaths” method. Again this didn’t work. And the same exception arises. Am hoping you can give some help…
This doesn’t work for me also…
Font font= FontRepository.openFont(“fonts/Arial.ttf”);
font.setEmbedded(true);
@ngzhongcai,
Please make sure, you are using full path for open font like “C://FontName.ttf”. Below example demonstrates how to open font and replace the font of text of first page.
// Open font
Font font = FontRepository.openFont("C:\\WINDOWS\\Fonts\\arial.ttf");
// Open document
Document doc = new Document("E:\\temp\\input.pdf");
// Create TextFragmentAbsorber object to find all "Lorem ipsum" text occurrences
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Lorem ipsum");
// Accept the absorber for first page
doc.getPages().get_Item(1).accept(absorber);
// Change font of the first text occurrence
absorber.getTextFragments().get_Item(1).getTextState().setFont ( font);
// Save document
doc.save("E:\\temp\\output.pdf");
input.pdf (1.3 MB)
output.pdf (1.3 MB)
Thank you Naeem,
Am terribly sorry to trouble you.
But I am at a loss.
Below is my code snippet. I am trying to digitally sign a PDF document that is empty. It’s a blank white page. At nowhere is there any text snippets. “FontNotFoundException” happens when I try to save the pdfFileSignature.
byte[] pdfBytes= Base64.getDecoder().decode((String)event.get("body>>pdf"));
InputStream pdfInputStream= new ByteArrayInputStream(pdfBytes);
ByteArrayOutputStream pdfOutputStream= new ByteArrayOutputStream();
PdfFileSignature pdfFileSignature= new PdfFileSignature();
pdfFileSignature.bindPdf(pdfInputStream);
byte[] imageBytes= Base64.getDecoder().decode((String)event.get("body>>image"));
InputStream imageInputStream= new ByteArrayInputStream(imageBytes);
pdfFileSignature.setSignatureAppearanceStream(imageInputStream);
byte[] keyBytes= Base64.getDecoder().decode((String)event.get("body>>key"));
InputStream keyInputStream= new ByteArrayInputStream(keyBytes);
PKCS1 key= new PKCS1(keyInputStream, (String)event.get("user>>sigPassword"));
Rectangle rectangle= new Rectangle(100, 200, 300, 300);
pdfFileSignature.sign(1, true, rectangle, key);
Font font= FontRepository.openFont("fonts/Arial.ttf");
TextFragmentAbsorber absorber= new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts));
pdfFileSignature.getDocument().getPages().get_Item(1).accept(absorber);
System.out.println(absorber.getTextFragments().size());
absorber.getTextFragments().get_Item(1).getTextState().setFont(font);
pdfFileSignature.save(pdfOutputStream);
Hi Naeem,
I finally got it working. Thank you for the patience!
I added the .tff font file into resource folder.
Lambda’s designated HOME is “/var/task/”.
List list= Document.getLocalFontPaths();
list.add("/var/task/fonts/");
Document.setLocalFontPaths(list);
@ngzhongcai,
We are glad to hear that your problem is solved. For any further query, please feel free to contact.
Hi @ngzhongcai
How did you add extra fonts ?
I am also working on AWS Lambda and getting FontNotFoundException.
list.add("/var/task/fonts/");
This is just a path to the folder.
Are the fonts actually already there ?
Let me know .
Thanks
@shamikjv
Thanks for posting your inquiry.
Please note that the required font should be present/installed on the machine where you are using the API. Please make sure that fonts are present in the directory which path you are adding to the list. Please feel free to let us know if issue still persists.
Hi,
I’m having trouble with Arial font, but only for signing pdf. It was working before, and it seems it stopped after we increased version. I’m having method that initialize fonts for Aspose pdf, imports are from pdf package.
@Override
protected void initAdditinalFonts(AppProperties app) {
LOG.info("Initialising fonts for Pdf");
List<String> fontPaths = FontRepository.getLocalFontPaths();
fontPaths.add(app.getFontsDir());
FontRepository.setLocalFontPaths(fontPaths);
}
This line of code works
Font font= FontRepository.openFont(app.getFontsDir()+"Arial.ttf");
But signing still throws an error
com.aspose.pdf.exceptions.FontNotFoundException: Font Arial was not found
at com.aspose.pdf.FontRepository.findFont(Unknown Source)
at com.aspose.pdf.SignatureField.lI(Unknown Source)
at com.aspose.pdf.SignatureField.sign(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.lI(Unknown Source)
at com.aspose.pdf.facades.PdfFileSignature.save(Unknown Source)
at com.simploud.service.AsposePdfService.signDocument(AsposePdfService.java:335)
So do I need to add fonts to another place so that digSig function can see them?
@velicko91
We need to investigate this case. Are you facing this issue with every PDF and every PFX file while signing? Can you please share a sample PDF and other sample files with us so that we can log the ticket in our issue tracking system and share the ID with you.
I’m signing this (62.7 KB)
document in a test, and signing is failing. Before it was working, not sure now with which version of aspose.pdf. Now we also have total license. I also noticed that api was changed. Before it was
List list= Document.getLocalFontPaths();
list.add("/var/task/fonts/");
Document.setLocalFontPaths(list);
but i’m adding new fonts this way:
List<String> fontPaths = FontRepository.getLocalFontPaths();
fontPaths.add(app.getFontsDir());
FontRepository.setLocalFontPaths(fontPaths);
@velicko91
We have logged an investigation ticket as PDFJAVA-42169 in our issue tracking system for further analysis. We will look into its details and let you know once the ticket is resolved. We will also let you know in case we need more information from your side. Please be patient and spare us some time.
We are sorry for the inconvenience.
Are there any news about PDFJAVA-42169?
@velicko91
We are afraid that the earlier logged ticket has not been yet resolved due to other pending issues in the queue. As soon as we make some progress toward ticket resolution, we will inform you here. Please spare us some time.
We are sorry for the inconvenience.
Hi @asad.ali
Are there any news about this ticket?