---------- Forwarded message ----------
From: Neus Arbó <[email protected]>
Date: 2016-11-21 10:27 GMT+01:00
Subject: Printing PDF with Acroform don't work
To: [email protected]
Hi,
I need help with an issue.
I'm filling an Acroform using Java and then I need to print it.
Using pdfbox 1.8.12 it all works as expected (when printing the pdf with
the Acroform, all the information filled using Java was printed too).
I upgrade to pdfbox 2.0.3 because I had problems with some fonts and it was
solved in the new version. But now, when I print the acroform it only
prints the static text, not the fields filled in java!
Next is the code I'm using:
PDDocument pdfDocument;
try {
pdfDocument = PDDocument.load(PrintUtils.class.getClassLoader().
getResourceAsStream("\\application\\vistes\\clients\\contractes\\informes\\
CONTRACTE.pdf"));
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
AcroForm.omplirCamp(acroForm, "num_contracte", contracte.getId());
AcroForm.omplirCamp(acroForm, "identificacio_caldera",
(contracte.getMarca() + " " + contracte.getAparell() + " " +
contracte.getNumero_fabricacio()).trim());
AcroForm.omplirCamp(acroForm, "data_instalacio",
dataFormatter.format(contracte.getDataInstalacio()));
AcroForm.omplirCamp(acroForm, "nom_usuari",
contracte.getNom_usuari());
AcroForm.omplirCamp(acroForm, "nom_usuari2",
contracte.getNom_usuari());
AcroForm.omplirCamp(acroForm, "nif", contracte.getNif());
AcroForm.omplirCamp(acroForm, "carrer", contracte.getDireccio());
AcroForm.omplirCamp(acroForm, "num_casa", contracte.getNumeroCasa());
AcroForm.omplirCamp(acroForm, "telefon", contracte.getTelefon());
AcroForm.omplirCamp(acroForm, "municipi", contracte.getPoblacio());
AcroForm.omplirCamp(acroForm, "euros", decimalFormatter.format(
contracte.getCost_anual()));
//Create AttributeSet
PrintRequestAttributeSet pset = new
HashPrintRequestAttributeSet();
//Add Duplex Option to AttributeSet
pset.add(Sides.DUPLEX);
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("Contracte " + (contracte.getId() != null ?
contracte.getId() : "nou"));
PageFormat format = job.getPageFormat(pset);
format.setOrientation(PageFormat.PORTRAIT);
Paper paper = new Paper();
paper.setSize(20, 14.5);
format.setPaper(paper);
job.defaultPage(format);
job.setPageable(new PDFPageable(pdfDocument));
if (job.printDialog(pset)) {
job.print(pset);
}
pdfDocument.close();
} catch (IOException e) {
e.printStackTrace();
} catch (PrinterException e) {
e.printStackTrace();
}
public static void omplirCamp(PDAcroForm acroForm, String nomCamp, String
valor) throws IOException{
PDField field = acroForm.getField(nomCamp);
if( field != null ) {
field.setValue(valor != null ? valor : "");
}
else {
System.err.println( "No s'ha trobat el camp "+nomCamp+"!");
}
}
I tried also to save the file and print it using FIle. It is saved ok, with
all fields filled. But when I print it, it is not printing the fields
neither.
The PDF I'm using is attached in this mail.
Am I doing something wrong or it is a bug???
Thank you!
Neus
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]