Parent Categories/Forums: iText - General : iTextSharp : iText, a JAVA-PDF library
Edit this Forum

Copy an existing pdf file and add new layer whit itext API for java

Search:
This forum is an archive for the mailing list: itext-questions@lists.sourceforge.net (mailing list options). Messages posted here will be sent to this mailing list.

Hi,

I need to modify a pdf file that contains layers inside, I use the PdfStamper for import this pdf, but i don`t add a new layer in the new pdf document generated.

This is the java code:

public class pdfStamper {

        public static void main(String[] args) {
                try
                {

                        PdfReader reader = new PdfReader("c:/esriMap.pdf");
                        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("c:/esriMapStamper.pdf"));
                        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
                                                BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                        PdfWriter writer = stamper.getWriter();
                        PdfLayer layer = new PdfLayer("Formato impresion", writer);
                        PdfContentByte over;
                        over = stamper.getOverContent(1);
                        over.saveState();
                        over.beginText();
                        over.moveText(60, 50);
                        over.setFontAndSize(bf, 8);
                        over.showText("INVENTARIO Y DIAGNOSTICO");
                                over.endText();
                        Image img1 = Image.getInstance("c:/alcaldia.jpg");
                        img1.setAbsolutePosition(490, 50);
                        over.beginLayer(layer);
                        over.addImage(img1);
                        over.rectangle(50,45,500,40);
                        over.endLayer();
                        over.restoreState();
                        over.stroke();
                }
                stamper.close();
                       
                } catch (IOException e) {
                        e.printStackTrace();
                } catch (DocumentException e) {
                        e.printStackTrace();
                }
        }
}

Thanks for your comments.
Child Forums (0): None
Post to Copy an existing pdf file and add new layer whit itext API for java Post New Message  ::  Alert me of new posts  ::  Rating Filter:

Thread (0 Threads) Rating Replies Last Message
Post to Copy an existing pdf file and add new layer whit itext API for java Post New Message  ::  Alert me of new posts  ::  Atom feed for Copy an existing pdf file and add new layer whit itext API for java