You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Eugene Chang <EC...@bonafide.com> on 2012/10/05 22:26:42 UTC

Font being changed after form field is set

Hi,

We have encounter a problem when using pdfbox.

We have a pdf form with fields and font set to Courier (please see attached pdf file PRP.pdf).

After running the program below which tries to set the value of one of the fields, font was being changed to Helvetica (please see attached pdf file forms26916.pdf).

Is there any way we can set the values and retain the original font?


Regards,


Eugene




package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


RE: Font being changed after form field is set

Posted by Eugene Chang <EC...@bonafide.com>.
I tried, but it does not solve the problem.

Thanks anyway.


-----Original Message-----
From: Joe Lee [mailto:joe_h_lee@yahoo.com] 
Sent: Thursday, October 11, 2012 2:06 PM
To: users@pdfbox.apache.org
Subject: Re: Font being changed after form field is set

Please check this attached Email information. I have similar problem as yours. Try to apply the patch stated in PDFBOX-1402 bug report. It helps my problem to some degree but not fully fix the problem.

Joe Lee

-------------------------------------------------------------------------------------

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

Will May commented on PDFBOX-1419:
----------------------------------

This is a duplicate of PDFBOX-1402. The current implementation doesn't handle zero font size (which means 'auto' font size) and multi-line text boxes correctly (it also doesn't break long lines either).
The patch I've attached to the PDFBOX-1402 doesn't position the text or select the correct font size perfectly but is a significantly better than the current implementation.
                
> PDField.setValue is not behave correctly
> ----------------------------------------
>
>                Key: PDFBOX-1419
>                URL: https://issues.apache.org/jira/browse/PDFBOX-1419
>            Project: PDFBox
>          Issue Type: Bug
>          Components: Writing
>    Affects Versions: 1.7.0
>        Environment: JavaEE 1.6 project developed under Window system, will deploy to Unix Weblogic server
>            Reporter: Joe Lee
>
> Use a template PDF file to write value into different fields (type of PDTextbox, PDCheckbox, PDChoiceField). The PDTextbox displays either very large font or not show anything. If click into the field, it displays correctly. Click outside the field, it reverts back to the wrong display. The same logic of code works well with iText library. The code similar to:
>            
>            PDFTemplate = PDDocument.load("myTemplate.pdf");
>            PDDocumentCatalog docCatalog = PDFTemplate.getDocumentCatalog();
>            PDAcroForm acroForm = docCatalog.getAcroForm();
>            :
>            try { PDField pdField = acroForm.getField(field);
>                    if (pdField != null) pdField.setValue(value);
>            } catch(...){}
>            :



________________________________
 From: Eugene Chang <EC...@bonafide.com>
To: "users@pdfbox.apache.org" <us...@pdfbox.apache.org> 
Sent: Thursday, October 11, 2012 11:11 AM
Subject: RE: Font being changed after form field is set
 
Hi,

                First I would like to thank Kishore for answering my question, but I think I did not state my problem clearly. So I am going to try one more time.


1.       We have a predefined PDF form, with text fields in it.

a.       We used Adobe Acrobat Professional to create the PDF form.

2.       The font set in the predefined fields are COURIER

a.       We choose COURIER because of its mono-spaced feature

3.       We want to set the values in predefined form fields.

So we used pdfbox

1.       Load the pdf form

2.       Set the value

But the problem now is the original font got changed after setting the value.

The link Kishore referenced is trying to create new field with font and place it on the pdf, but our requirement is setting values on existing fields and retain original font.

The original files and tested file:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html


The code:

package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}




Regards,

Re: Font being changed after form field is set

Posted by Joe Lee <jo...@yahoo.com>.
Please check this attached Email information. I have similar problem as yours. Try to apply the patch stated in PDFBOX-1402 bug report. It helps my problem to some degree but not fully fix the problem.

Joe Lee

-------------------------------------------------------------------------------------

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

Will May commented on PDFBOX-1419:
----------------------------------

This is a duplicate of PDFBOX-1402. The current implementation doesn't handle zero font size (which means 'auto' font size) and multi-line text boxes correctly (it also doesn't break long lines either).
The patch I've attached to the PDFBOX-1402 doesn't position the text or select the correct font size perfectly but is a significantly better than the current implementation.
                
> PDField.setValue is not behave correctly
> ----------------------------------------
>
>                Key: PDFBOX-1419
>                URL: https://issues.apache.org/jira/browse/PDFBOX-1419
>            Project: PDFBox
>          Issue Type: Bug
>          Components: Writing
>    Affects Versions: 1.7.0
>        Environment: JavaEE 1.6 project developed under Window system, will deploy to Unix Weblogic server
>            Reporter: Joe Lee
>
> Use a template PDF file to write value into different fields (type of PDTextbox, PDCheckbox, PDChoiceField). The PDTextbox displays either very large font or not show anything. If click into the field, it displays correctly. Click outside the field, it reverts back to the wrong display. The same logic of code works well with iText library. The code similar to:
>            
>            PDFTemplate = PDDocument.load("myTemplate.pdf");
>            PDDocumentCatalog docCatalog = PDFTemplate.getDocumentCatalog();
>            PDAcroForm acroForm = docCatalog.getAcroForm();
>            :
>            try { PDField pdField = acroForm.getField(field);
>                    if (pdField != null) pdField.setValue(value);
>            } catch(...){}
>            :



________________________________
 From: Eugene Chang <EC...@bonafide.com>
To: "users@pdfbox.apache.org" <us...@pdfbox.apache.org> 
Sent: Thursday, October 11, 2012 11:11 AM
Subject: RE: Font being changed after form field is set
 
Hi,

                First I would like to thank Kishore for answering my question, but I think I did not state my problem clearly. So I am going to try one more time.


1.       We have a predefined PDF form, with text fields in it.

a.       We used Adobe Acrobat Professional to create the PDF form.

2.       The font set in the predefined fields are COURIER

a.       We choose COURIER because of its mono-spaced feature

3.       We want to set the values in predefined form fields.

So we used pdfbox

1.       Load the pdf form

2.       Set the value

But the problem now is the original font got changed after setting the value.

The link Kishore referenced is trying to create new field with font and place it on the pdf, but our requirement is setting values on existing fields and retain original font.

The original files and tested file:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html


The code:

package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}




Regards,

RE: Font being changed after form field is set

Posted by Eugene Chang <EC...@bonafide.com>.
Hi,

                First I would like to thank Kishore for answering my question, but I think I did not state my problem clearly. So I am going to try one more time.


1.       We have a predefined PDF form, with text fields in it.

a.       We used Adobe Acrobat Professional to create the PDF form.

2.       The font set in the predefined fields are COURIER

a.       We choose COURIER because of its mono-spaced feature

3.       We want to set the values in predefined form fields.

So we used pdfbox

1.       Load the pdf form

2.       Set the value

But the problem now is the original font got changed after setting the value.

The link Kishore referenced is trying to create new field with font and place it on the pdf, but our requirement is setting values on existing fields and retain original font.

The original files and tested file:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html


The code:

package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}




Regards,



From: Kishore Babu [mailto:kbabu@envistacorp.com]
Sent: Thursday, October 11, 2012 4:34 AM
To: users@pdfbox.apache.org
Subject: RE: Font being changed after form field is set


Check the following links, may be helpful to set the fonts

http://mail-archives.apache.org/mod_mbox/pdfbox-users/201205.mbox/%3C71D208C6BCAFAA419A4A9F7B58FA4D82126298D2@HSMSX03.iheiler.com%3E

http://stackoverflow.com/questions/8129451/write-text-into-ploygon-with-pdfbox



[cid:image002.jpg@01CDA7D2.688F6090]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image004.jpg@01CDA7D2.688F6090]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image006.jpg@01CDA7D2.688F6090] <http://twitter.com/enVistaSpplyChn>    [cid:image008.jpg@01CDA7D2.688F6090] <http://www.linkedin.com/companies/envista>





[cid:image010.jpg@01CDA7D2.688F6090]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Wednesday, 10 October, 2012 8:38 PM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: RE: Font being changed after form field is set

Sure, attached are the file.
                PRP.pdf
is the original file with Courier font
                forms26916.pdf
is the data populated form, and font got changed

Actually I attached the two files in my original email, in case you cannot see the attached files, I have uploaded to a file sharing site, below are the links:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html

Regards,




From: Kishore Babu [mailto:kbabu@envistacorp.com]
Sent: Wednesday, October 10, 2012 6:13 AM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: RE: Font being changed after form field is set


Could you please send the original pdf file?


Regards,
[cid:image001.jpg@01CDA717.188072D0]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image002.jpg@01CDA717.188072D0]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image003.jpg@01CDA717.188072D0] <http://twitter.com/enVistaSpplyChn>    [cid:image004.jpg@01CDA717.188072D0] <http://www.linkedin.com/companies/envista>





[cid:image005.jpg@01CDA717.188072D0]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Saturday, 06 October, 2012 1:57 AM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: Font being changed after form field is set

Hi,

We have encounter a problem when using pdfbox.

We have a pdf form with fields and font set to Courier (please see attached pdf file PRP.pdf).

After running the program below which tries to set the value of one of the fields, font was being changed to Helvetica (please see attached pdf file forms26916.pdf).

Is there any way we can set the values and retain the original font?


Regards,


Eugene




package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


RE: Font being changed after form field is set

Posted by Kishore Babu <kb...@envistacorp.com>.
Check the following links, may be helpful to set the fonts

http://mail-archives.apache.org/mod_mbox/pdfbox-users/201205.mbox/%3C71D208C6BCAFAA419A4A9F7B58FA4D82126298D2@HSMSX03.iheiler.com%3E

http://stackoverflow.com/questions/8129451/write-text-into-ploygon-with-pdfbox



[cid:image002.jpg@01CDA7D2.688F6090]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image004.jpg@01CDA7D2.688F6090]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image006.jpg@01CDA7D2.688F6090] <http://twitter.com/enVistaSpplyChn>    [cid:image008.jpg@01CDA7D2.688F6090] <http://www.linkedin.com/companies/envista>





[cid:image010.jpg@01CDA7D2.688F6090]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Wednesday, 10 October, 2012 8:38 PM
To: users@pdfbox.apache.org
Subject: RE: Font being changed after form field is set

Sure, attached are the file.
                PRP.pdf
is the original file with Courier font
                forms26916.pdf
is the data populated form, and font got changed

Actually I attached the two files in my original email, in case you cannot see the attached files, I have uploaded to a file sharing site, below are the links:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html

Regards,




From: Kishore Babu [mailto:kbabu@envistacorp.com]
Sent: Wednesday, October 10, 2012 6:13 AM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: RE: Font being changed after form field is set


Could you please send the original pdf file?


Regards,
[cid:image001.jpg@01CDA717.188072D0]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image002.jpg@01CDA717.188072D0]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image003.jpg@01CDA717.188072D0] <http://twitter.com/enVistaSpplyChn>    [cid:image004.jpg@01CDA717.188072D0] <http://www.linkedin.com/companies/envista>





[cid:image005.jpg@01CDA717.188072D0]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Saturday, 06 October, 2012 1:57 AM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: Font being changed after form field is set

Hi,

We have encounter a problem when using pdfbox.

We have a pdf form with fields and font set to Courier (please see attached pdf file PRP.pdf).

After running the program below which tries to set the value of one of the fields, font was being changed to Helvetica (please see attached pdf file forms26916.pdf).

Is there any way we can set the values and retain the original font?


Regards,


Eugene




package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


RE: Font being changed after form field is set

Posted by Eugene Chang <EC...@bonafide.com>.
Sure, attached are the file.
                PRP.pdf
is the original file with Courier font
                forms26916.pdf
is the data populated form, and font got changed

Actually I attached the two files in my original email, in case you cannot see the attached files, I have uploaded to a file sharing site, below are the links:

http://www.2shared.com/document/auMD40In/PRP.html

http://www.2shared.com/document/SdnqJEFO/forms26916.html

Regards,




From: Kishore Babu [mailto:kbabu@envistacorp.com]
Sent: Wednesday, October 10, 2012 6:13 AM
To: users@pdfbox.apache.org
Subject: RE: Font being changed after form field is set


Could you please send the original pdf file?


Regards,
[cid:image001.jpg@01CDA717.188072D0]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image002.jpg@01CDA717.188072D0]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image003.jpg@01CDA717.188072D0] <http://twitter.com/enVistaSpplyChn>    [cid:image004.jpg@01CDA717.188072D0] <http://www.linkedin.com/companies/envista>





[cid:image005.jpg@01CDA717.188072D0]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Saturday, 06 October, 2012 1:57 AM
To: users@pdfbox.apache.org<ma...@pdfbox.apache.org>
Subject: Font being changed after form field is set

Hi,

We have encounter a problem when using pdfbox.

We have a pdf form with fields and font set to Courier (please see attached pdf file PRP.pdf).

After running the program below which tries to set the value of one of the fields, font was being changed to Helvetica (please see attached pdf file forms26916.pdf).

Is there any way we can set the values and retain the original font?


Regards,


Eugene




package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


RE: Font being changed after form field is set

Posted by Kishore Babu <kb...@envistacorp.com>.
Could you please send the original pdf file?


Regards,
[cid:image001.jpg@01CDA717.188072D0]<http://www.envistacorp.com/>






Kishore Babu I Developer
email: kbabu@envistacorp.com<ma...@envistacorp.com>
office: 040.66417681
www.envistacorp.com<http://www.envistacorp.com>
Subscribe<http://pages.exacttarget.com/page.aspx?QS=472529ec60bdf32a36ac1f221ebc1706b66778f96833e451f77fe13f8e4cf0db> to enVista's Newsletter!

[cid:image002.jpg@01CDA717.188072D0]<http://www.facebook.com/home.php?#%21/pages/enVista/281494945342?ref=search>   [cid:image003.jpg@01CDA717.188072D0] <http://twitter.com/enVistaSpplyChn>    [cid:image004.jpg@01CDA717.188072D0] <http://www.linkedin.com/companies/envista>





[cid:image005.jpg@01CDA717.188072D0]<http://www.inc.com/inc5000/profile/envista>







From: Eugene Chang [mailto:EChang@bonafide.com]
Sent: Saturday, 06 October, 2012 1:57 AM
To: users@pdfbox.apache.org
Subject: Font being changed after form field is set

Hi,

We have encounter a problem when using pdfbox.

We have a pdf form with fields and font set to Courier (please see attached pdf file PRP.pdf).

After running the program below which tries to set the value of one of the fields, font was being changed to Helvetica (please see attached pdf file forms26916.pdf).

Is there any way we can set the values and retain the original font?


Regards,


Eugene




package lab;

import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();

            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


Re: Font being changed after form field is set

Posted by Duane Nickull <du...@technoracle-systems.com>.
PDF's have embedded fonts and system fonts.  This is a complex topic (I used
to work at Adobe for 8 years).   It may be possible that the fonts are not
available although in this case, courier is very common so I cannot see the
issue.

I want to respect the list's policy on promoting commercial software but if
you want  to discuss offline, I am available.  Technoracle (my post- Adobe
company) is comprised of many ex-Adobe PDF experts and we have perfected
some solutions for rendering PDF forms on mobile.  Nevertheless, I am here
in this forum to share expertise when I can so I will focus on that first.

BTW the attachment never came through.  If you resend, I be more than happy
to help you for free as a community member.  Our emphasis is on mobile
anyways so 

Duane Nickull
***********************************
Technoracle Advanced Systems Inc.
Consulting and Contracting; Proven Results!
i.  Neo4J, PDF, Java, LiveCycle ES, Flex, AIR, CQ5 & Mobile
b. http://technoracle.blogspot.com
t.  @duanechaos
"Don't fear the Graph!  Embrace Neo4J"



From:  Eugene Chang <EC...@bonafide.com>
Reply-To:  <us...@pdfbox.apache.org>
Date:  Friday, 5 October, 2012 10:26 PM
To:  "users@pdfbox.apache.org" <us...@pdfbox.apache.org>
Subject:  Font being changed after form field is set

Hi,
 
We have encounter a problem when using pdfbox.
 
We have a pdf form with fields and font set to Courier (please see attached
pdf file PRP.pdf).
 
After running the program below which tries to set the value of one of the
fields, font was being changed to Helvetica (please see attached pdf file
forms26916.pdf).
 
Is there any way we can set the values and retain the original font?
 
 
Regards,
 
 
Eugene
 
 
 
 
package lab;
 
import java.io.File;
 
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 
public class TestBed1 {
    public static void main(String[] args) {
        try {
            PDDocument pdfDocument = PDDocument.load("C:/Temp/pdf/PRP.pdf");
            PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();
            acroForm.getField("officeAfterHourAndTollFree").setValue(
                    "Phone: (805) 777-7666  Fax: (805) 777-9876");
            File file = File.createTempFile("forms", ".pdf");
            pdfDocument.save(file.getCanonicalPath());
            pdfDocument.close();
 
            System.out.println(file.getCanonicalPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}