Hi support,
I’m trying to convert a PDF created by Words (I’m working on Linux), and I have to subsitute Windows’s font by another (ie Substitute Calibri by Carlito).
I defined the replacement like this :
FontRepository.getSubstitutions().add(new SimpleFontSubstitution(“Calibri”,“Carlito”));
But when I convert document, any font has been replaced.
In my original PDF, name of Calibri is ABCDEE+Calibri so how can I replace it ?
If I modified Calibri by ABCDEE+Calibri it’s work fine but in some case prefix are not ABCDEE. I’ve the same issue with other fonts.
Regards,
Florian Mélot
Hi Florian,
Hi Nayyer,
The PDF file has been generated with MS Word (I’ve attached it to this message)
I’m working on a converter which could convert any types of documents into another types of documents (some conversions are impossible) with the help of aspose.
My functionnal needed is to replace copyrighted font by free font (like Calibri / Carlito) so I’ve created a PDF based on docx document to test my application.
In some case, PDF file could be generate with embedded fonts and fonts could be prefix by some characters (generated by an algorithm). Here, prefix is ABCDEE (http://stackoverflow.com/questions/13082117/is-there-a-regex-for-pdf-font-family-and-font-names).
If I specify Calibri like orignal font and Carlito in substitution font in SimpleFontSubstitution it’s doesn’t work.
If I specify ABCDEE+Calibri (in my case), it’s work fine but prefixe (ABCDEE) are only available to this PDF.
How can I specifiy Calibri font will be replace by Carlito without prefixe ? Another class / method with regexp ?
I’ve also another questions about substitutions. I manage a XML file to load map to replace font. If I haven’t substitution font in my folder font, conversion raise an exception without information and it’s really hard to find the cause of this exception (trace is below). Is it possible to add some informations about NPE ?
java.lang.NullPointerException
at com.aspose.pdf.internal.p64.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p64.z7.m2(Unknown Source)
at com.aspose.pdf.internal.p64.z1.m2(Unknown Source)
at com.aspose.pdf.internal.p66.z6.m2(Unknown Source)
at com.aspose.pdf.internal.p110.z1.m2(Unknown Source)
at com.aspose.pdf.internal.p110.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p110.z1.m2(Unknown Source)
at com.aspose.pdf.internal.p110.z1.m1(Unknown Source)
at com.aspose.pdf.internal.p110.z6.m1(Unknown Source)
at com.aspose.pdf.internal.p110.z6.m1(Unknown Source)
at com.aspose.pdf.internal.p110.z6.m18(Unknown Source)
at com.aspose.pdf.internal.p110.z6.m2(Unknown Source)
at com.aspose.pdf.internal.p110.z7.m13(Unknown Source)
at com.aspose.pdf.internal.p110.z6.m1(Unknown Source)
at com.aspose.pdf.ADocument.m1(Unknown Source)
at com.aspose.pdf.Document.m1(Unknown Source)
at com.aspose.pdf.ADocument.convertInternal(Unknown Source)
at com.aspose.pdf.Document.convertInternal(Unknown Source)
at com.aspose.pdf.ADocument.convert(Unknown Source)
at com.aspose.pdf.Document.convert(Unknown Source)
Thanks in advance,
Florian Mélot
The same problem is present when I try to replace manually font (picked from http://www.aspose.com/docs/display/pdfjava/Replace+Text+in+a+PDF+Document#ReplaceTextinaPDFDocument-ReplacefontsinexistingPDFfile)
Hi Florian,
In the same way, when I define FreeMono as substitute of Courier, it’s work fine for texts are in Courier but not working for text in Courier Bold.
It’s annoying to define correspondence for each type (italic, bold, italic bold, regular).
Hi Florian,
// Load existing PDF Document<o:p></o:p>
Document pdf = new Document("c:/pdftest/Multiples+polices (1).pdf");
// Search text fragments and set edit option as remove unused fonts
TextFragmentAbsorber absorber = new TextFragmentAbsorber(new TextEditOptions(TextEditOptions.FontReplace.RemoveUnusedFonts));
// accept the absorber for all the pages
pdf.getPages().accept(absorber);
// traverse through all the TextFragments
TextFragmentCollection textFragmentCollection = absorber.getTextFragments();
for (java.util.Iterator iterator = textFragmentCollection.iterator(); iterator.hasNext();) {
TextFragment textFragment = iterator.next();
String fontName = textFragment.getTextState().getFont().getFontName();
// if the font name is ArialMT, replace font name with Arial
//if (fontName.equals("ArialMT")) {
textFragment.getTextState().setFont(FontRepository.findFont("Calibri"));
//}
}
// Save the updated document
pdf.save(“c:/pdftest/Multiples+polices
(1)_output.pdf”);
@codewarior So when can I do a simple substitution.
I am converting PDF to HTML and I want to do quick substitution.
Here are the steps:
- I do pdf.getFontUtilities().getAllFonts(); to get all fonts from a document.
- Check the directory if those fonts exists or not
- If they do not exist i add the command
FontRepository.getSubstitutions().add(new SimpleFontSubstitution(fontName, "Times New Roman"));
- Then I do
pdf.save(file, options)
. - Yet it throws font not found exception.
- do I have to do TextFragmentAbsorber and setFont all the time ?
Thanks for contacting support.
Would you please share your sample HTML file along with complete sample code snippet. We will test the scenario in our environment and address it accordingly.