iText PDF values not shown on iOS - java

We create PDF files with iText (in Java) which are working fine on Windows / Android, however when we open such file on an iPhone the acroFields that were set in the code are empty.
We are using the following code and the setGenerateAppearances is already set to true.
PdfStamper pdfStamper = new PdfStamper(templateReader, pagePdf);
AcroFields acroFields = pdfStamper.getAcroFields();
acroFields.setGenerateAppearances(true);
acroFields.setField("creationdate", creationDate);
Any idea why this isn't working on the iPhone but it does work on all other devices?
Thanks

As stated by Bruno Lowagie, the issue can be resolved by using the flatten option, which should be set before the pdfStamper.close() has been called:
// flatten the PDF (so the values are visible when PDF is downloaded on iOS / OS X)
pdfStamper.setFormFlattening(true);

Related

pdf creation on Android: what is the difference between PdfDocument and PdfPrintedDocument

I want to create a pdf file in my Android app.
What is the difference between these two classes ?
https://developer.android.com/reference/android/graphics/pdf/PdfDocument
https://developer.android.com/reference/android/print/pdf/PrintedPdfDocument.html
Thanks !

Regd. The font 'ABCDEE+Calibri' contains bad/widts on Unix/Linux

Greetings for the Day :)
I am working on PdfBox and generated PDF successfully as per requirement on Windows. But when running my solution on Unix/Linux and it is generating the PDFs as per requirement. When we tried to open the PDF with Adobe Acrobat Reader DC version it is giving Pop-up The font 'ABCDEE+Calibri' contains bad/widts. I moved the PDF to windows from linux and tried to open the pdf , now its poping up on windows as well. I have not used calibri anywhere on my pdf. I used TrueTypeFont to load.ttc file as .ttf file. Apart from that there is no great logic as well.
Map<String, PDFont> suppFonts = new HashMap<>();
PDFont arial = PDType0Font.load(pddoc, <<className>>.class.getResourceAsStream("/path/to/the/file.ttf").getInputStream());
PDFont mingliu = PDType0Font.load(pddoc, new TrueTypeCollection(<<className>>.class.getResourceAsStream("/path/to/the/file.ttc").getInputStream());
suppFonts .put("arial",arial);
suppFonts .put("mingliu",mingliu);
we used this HashMap and retrieved font with the name we have given such as arial,mingliu..etc.
Please help me if you have faced such kind of issue earlier.

Font different in MS Edge than Chrome for PDF when using PDFBox

I have a PDF template created in Acrobat Reader DC which contains a field that I trying to fill with some text. The field has a specific font that I want to keep. I am able to obtain the field and change the value.
However, when I open the PDF in Internet Explorer the font is a default font. The confusing part is that if I open it in Chrome then it shows the correct font. Not sure why that is, any help is appreciated. I am using PDFBox version 2.
(The font works if I don't use Java to edit the file, if I just manually change it inside Acrobat and save the file then it shows correctly.)
See below for the code used.
File file = new File("PDFToReadFrom.pdf");
PDDocument pdDoc = PDDocument.load(file);
PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
PDAcroForm pdAcroForm = pdCatalog.getAcroForm();
for(PDField pdField : pdAcroForm.getFields()){
pdField.setValue("value");
}
pdDoc.save(new File("test.pdf"));
pdDoc.close();
I suggest you'd better to compare the PDF file (Use Java edited file and the Acrobat generated file), whether they are using the same font.
According to this article, it seems that we could set the font when using PDFBox to create a PDF file.

Open PDF File with Adobe Acrobat inside Java Application (via OLE)

I would like to open a PDF File inside an existing Java(SWT)-Application. The PDF should not opened in an external frame. I tried via the OLE interface but without success.
clientSite = new OleControlSite(frame, SWT.NONE, "AcroExch.App", fileName);
automation = new OleAutomation(clientSite);
clientSite.doVerb(OLE.OLEIVERB_OPEN);
you can use the IE Interface and then navigate to the PDF file.
Pseudocode:
$Obj = ObjCreate("Shell.Explorer.2")
$Obj.Navigate('D:\Test.pdf')
or the Reader Web Interface
Pseudocode:
$oReader = ObjCreate("AcroPDF.PDF.1")
$oReader.Load("D:\Test.pdf")
How you bind the object into your Java-GUI you may ask under java
HTH, Reinhard
PS: the "Shell.Explorer.2" option mostly works for me better.

PDF export printing in Internet Explorer

protected static byte[] exportReportToPdf(JasperPrint jasperPrint)
throws JRException {
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,
"this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
exporter.exportReport();
return baos.toByteArray();
}
We are using code like this to export a PDF document from a Jasper application.
The line
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,
"this.print({bUI: true,bSilent: false,bShrinkToFit: true});");
adds JavaScript to send the PDF document directly to the printer.
The expected behavior is that a print dialog will come up with a preview of the PDF document.
This works fine most of the time - except I am having problems about one out of every 5-6 times in Internet Explorer 8 and Firefox.
What happens is - the print preview dialog with the PDF document does not appear or it appears with a blank document in the preview window.
-I've tried a number of different JavaScripts (different params to this.print() via exporter.setParameter
-I've tried setting different response headers such as
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; filename=\""
+ reportName
+ "\"");
response.setContentLength(baos.size());
these did not seem to help
This seems to be an IE and FF issue. Has anyone ever dealt with this problem? I need to get it to work across all browsers 100% of the time. Perhaps a different approach to accomplish the goal of sending the PDF document export directly to the printer? or a third party library that will work across browsers?
Maybe it isn't getting a chance to update the UI. The following code delays the print perhaps giving it the chance it needs. I didn't test as I don't have your environment.
exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,
"app.setTimeOut('this.print({bUI: true,bSilent: false,bShrinkToFit: true});',200);")

Categories