Hello, we use code sample from Developer Guide to replace text token in PDF (which is generated from MS Word). We update PDF and save it. It usually open correctly. But if we stream PDF from web server to browser IE 11 Acrobat Reader window is opened and randomly it shows general error dialog:
Hi Marek,
Thanks for contacting support. I have tested the scenario using Aspose.Pdf for Java 11.5.0 in Eclipse Juno project running over Windows 7 (x64) with JDK 1.7 and I am unable to notice any issue. During my testing, I have used Arial font as I did not have ExpertSans-Regular over my system. Can you please share some details regarding your working environment so that we can again try replicating the issue in our environment.
mslama2:
Note: I also filed separate report about growing file size during this operation which was accepted as bug here. Is it possible it could be somehow connected? PDF file size grows after simple replacement
We have already managed to reproduce the issue on above stated forum thread and once the problem is resolved, you will be updated in same thread. Furthermore, as both issues are separate, so its better to keep them apart in separate threads.
We are sorry for your inconvenience.
[Java]
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/Test_publication_3.pdf");
String textReplacement = "16 May 2016, 14:21 GMT";
com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("12 February 2016, 14:30 GMT");
com.aspose.pdf.TextSearchOptions textSearchOptions = new com.aspose.pdf.TextSearchOptions(true);
textFragmentAbsorber.setTextSearchOptions(textSearchOptions);
pdfDocument.getPages().accept(textFragmentAbsorber);
com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();
for (com.aspose.pdf.TextFragment textFragment : (Iterable<com.aspose.pdf.TextFragment>) textFragmentCollection) {
String foundText = textFragment.getText();
// Replace only when replacement text is different from original text
if (!foundText.equals(textReplacement)) {
textFragment.setText(textReplacement);
// Set other font for JP
com.aspose.pdf.Font font = com.aspose.pdf.FontRepository.findFont("Arial");
textFragment.getTextState().setFont(font);
}
}
pdfDocument.optimize();
pdfDocument.save("c:/pdftest/TextReplaced_11_5_0.pdf");
} catch (Exception ex) {
System.out.println(ex);
}
I added our font ExpertSans-Regular as attachment to original post. Please test with this.
FYI: I tested the same scenario with Arial font and it seems ok ie. I cannot reproduce issue I see with Expert Sans Regular font. What I do:
Hi Marek,
I tested more and it looks it happens only for Calibri font. When I replace text in Test_publication_3 I get file which fails with Adobe PDF Reader plugin in IE11. Opening in standalone Adobe Reader is ok ie. problem is only in plugin. I keep the same font and the same font size (it returns font size 11.04).
Cannot delete
Hi Marek,
I have some new info. My colleague tried to open updated PDF file in Adobe Acrobat 9.5.0 on Win7 and he gets following error dialog:
Hi Marek,
After investigation I found way how to reproduce locally. It has the same cause as in issue I reported Problem with PDF after adding image
Hi Marek,