AFAIK some of the information is only written out when the document is saved. So prior to sending the document to the printer you need to save it.
BR Maruan > Am 25.11.2016 um 15:11 schrieb Neus Arbó <[email protected]>: > > I'm using PDFBox 2.0.3 > > Here's 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.setNeedAppearances(false); > > 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+"!"); > } > } > > > 2016-11-25 12:18 GMT+01:00 Maruan Sahyoun <[email protected]>: > >> Hi, >> >>> Am 25.11.2016 um 11:14 schrieb Neus Arbó <[email protected]>: >>> >>> If I print the saved document the characters are good, not replaced. >> >> which version of PDFBox are you using? Could you share a snippet of how >> you go from the PDF template to form filling to printing? >> >> BR >> Maruan >> >> >>> >>> 2016-11-25 11:03 GMT+01:00 Maruan Sahyoun <[email protected]>: >>> >>>> Hi, >>>> >>>>> Am 25.11.2016 um 09:33 schrieb Neus Arbó <[email protected]>: >>>>> >>>>> Hi! >>>>> I have a problem with some fields filled using Java. >>>>> >>>>> If i set a string containing characters like óá, etc. in an Acroform >>>> field >>>>> when I send the pdf to the printer these characters are replaced by >>>>> another ones. But if I save the pdf to the disk, when I open the pdf >> the >>>>> characters are correct not replaced! >>>>> >>>> >>>> what happens if you print the saved document? >>>> >>>> BR >>>> Maruan >>>> >>>>> Here it is the pdf I'm using https://drive.google.com/file/d/0B1_3_ >>>>> sVPnBolbjc3U21LTUFTeDg/view?usp=sharing >>>>> >>>>> Any idea on how can I solve this? >>>>> >>>>> Thank you! >>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [email protected] >>>> For additional commands, e-mail: [email protected] >>>> >>>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

