You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/01/22 11:45:26 UTC

[jira] [Comment Edited] (PDFBOX-3620) Acroform fields bad encoding

    [ https://issues.apache.org/jira/browse/PDFBOX-3620?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15833464#comment-15833464 ] 

Tilman Hausherr edited comment on PDFBOX-3620 at 1/22/17 11:44 AM:
-------------------------------------------------------------------

I can confirm this with this code, the rendering of the produced file is bad:
{code}
        PDDocument doc = PDDocument.load(new File("CONTRACTE.pdf"));
        PDField field = doc.getDocumentCatalog().getAcroForm().getField("nom_usuari");
        field.setValue("äöüÄÖÜß");
        doc.save(new File("CONTRACTE2.pdf"));
{code}
In PDFDebugger, one can look at {{Root/AcroForm/DR/Font/F12}}, at 228 an "ä" glyph should be shown but it isn't.

I tested doing the same with the sample form in CreateSimpleForm.java and that one works fine, but that one uses a type1 standard 14 font.


was (Author: tilman):
I can confirm this with this code:
{code}
        PDDocument doc = PDDocument.load(new File("CONTRACTE.pdf"));
        PDField field = doc.getDocumentCatalog().getAcroForm().getField("nom_usuari");
        field.setValue("äöüÄÖÜß");
        doc.save(new File("CONTRACTE2.pdf"));
{code}
In PDFDebugger, one can look at {{Root/AcroForm/DR/Font/F12}}, at 228 an "ä" glyph should be shown but it isn't.

I tested doing the same with the sample form in CreateSimpleForm.java and that one works fine, but that one uses a type1 standard 14 font.

> Acroform fields bad encoding
> ----------------------------
>
>                 Key: PDFBOX-3620
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3620
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 2.0.3
>         Environment: Windows 7
>            Reporter: Neus
>              Labels: acroform
>
> There's a problem with acroform fields filled using Java.
> Setting a string containing characters like óá, etc. in an Acroform field,
> when sending the pdf to the printer these characters are replaced by
> another ones. But if the pdf is saved to the disk, when I open the pdf the
> characters are correct not replaced!
> Here it is the pdf I'm using https://drive.google.com/file/d/0B1_3_sVPnBolbjc3U21LTUFTeDg/view?usp=sharing
> Also I have tried to save the document in a temp file, read that
> file using pdfbox and send it to the printer and the characters like ó, é, etc. don't appear well neither.
> Here's the code I'm using
> {code}
> 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+"!");
> }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org