Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

Re: [iText-questions] Cannot print PDF after filling out form.

Frank Starsinic

2006-09-07

Replies:

Here is the method I wrote that takes an input PDF form, adds an image to a given form field, and writes it out as a different PDF.


    public static void createPDFWithImageInAcroField(String pInFile, String pOutFile, String pImageFile, String pPDFField) throws Exception       
    {
        if (pInFile==null || pOutFile==null || pImageFile==null || pPDFField==null) {              
            throw new Exception("Method createPDFWithImageInAcroField() requires non-NULL parameters"+
                            " for InputPDF, OutputPDF, ImageFile, and AcroFormFieldName");
        }
        PdfReader reader = new PdfReader(pInFile);
        PdfStamper stamper = new PdfStamper(reader,
                                            new FileOutputStream(pOutFile));
        AcroFields form = stamper.getAcroFields();
        float[] photograph = form.getFieldPositions(pPDFField);
        Rectangle rect = new Rectangle(
                                      photograph[1], photograph[2], photograph[3], photograph[4]);
        //Rectangle rect = new Rectangle(500,200,700,400);
        Image img = Image.getInstance(pImageFile);
        img.scaleToFit(rect.width(), rect.height());
        img.setAbsolutePosition(photograph[1]
                                + (rect.width() - img.scaledWidth()) / 2,
                                photograph[2]
                                + (rect.height() - img.scaledHeight()) / 2);
        PdfContentByte cb =
        //stamper.getOverContent((int)photograph[0]);
        stamper.getOverContent(1);
        cb.addImage (img);
        stamper.close();

    }

I will continue to investigate.

Thanks,
Frank



On 9/7/06, Frank Starsinic < frank.starsinic@gmail.com> wrote:
I did use a Stamper from your FAQ example on the website that added an image
centered and expanded to fill a field on a PDF.

I'll look closer at the API to see if I can see anything.

Thanks,
Frank




On 9/7/06, bruno <bruno@lowagie.com> wrote:
Frank Starsinic wrote:

> After populating a PDF with the AcroForm fields and then saving the
> PDF, the print icon is disabled and I can no longer print the PDF.
>
> Any assistance is appreciated.

As far as I know, this can only happen if you change the permission of
the file.
Did you perhaps copy a PdfStamper sample that has a line disabling the
print icon?
br,
Bruno

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions




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

Hand Crafted Magic
http://www.theambitiouscard.com/
------------------------------------------------------------------



--
------------------------------------------------------------------
Hand Crafted Magic
http://www.theambitiouscard.com/
------------------------------------------------------------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
©2008 junlu.com - Jax Systems, LLC, U.S.A.