Sign on more than one page iText

-2
Hello, I have an application that digitally signs PDF's using iText api I can sign on any page and anywhere, but I can not repeat the signature on all pages .. I tried to create a PdfAnnotation.createFreeText to copy the text of the signature and replicates it in the pages, but in the PDF reader of the computer it interprets differently from the browser. On the computer it is certain:

Inthebrowseritlosestheconfigurationoftheboxandgoesyellowasanote:

My question and how can I sign on all pages? and if it's not possible, how do I create a text field or something at the bottom of each page?

    
asked by anonymous 20.09.2018 / 14:33

1 answer

0

I was able to solve with the code below:

        filename = filename + "_signed.pdf";

        File fileToWrite = File.createTempFile(filename, null);
        reader = new PdfReader(this.file);

        fow = new FileOutputStream(fileToWrite);
        stamper = PdfStamper.createSignature(reader, fow, '
        filename = filename + "_signed.pdf";

        File fileToWrite = File.createTempFile(filename, null);
        reader = new PdfReader(this.file);

        fow = new FileOutputStream(fileToWrite);
        stamper = PdfStamper.createSignature(reader, fow, '%pre%0');

        Font fontcabecatable = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL);
        PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
        appearance.setLayer2Font(fontcabecatable);
        appearance.setLayer2Text(textoAss);
        appearance.setSignDate(Calendar.getInstance());

        Integer pageCount = Integer.valueOf(reader.getNumberOfPages());
        System.out.println("pageCount "+pageCount);


        if(position.equals("planoDeEnsino") ) {
            textoAss = "\n"+textoAss;

            for(int i = 2; i <= pageCount; i++) {
                PdfContentByte pcb = stamper.getUnderContent(i);
                Paragraph p = new Paragraph(textoAss);
                p.setFont(fontcabecatable);
                p.setLeading((float) 10);
                ColumnText ct = new ColumnText(pcb);
                ct.setSimpleColumn(positionSignature(position));
                ct.addElement(p);
                ct.go();
            }
        }

        appearance.setVisibleSignature(positionSignature(position),pagina, null);
0'); Font fontcabecatable = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL); PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setLayer2Font(fontcabecatable); appearance.setLayer2Text(textoAss); appearance.setSignDate(Calendar.getInstance()); Integer pageCount = Integer.valueOf(reader.getNumberOfPages()); System.out.println("pageCount "+pageCount); if(position.equals("planoDeEnsino") ) { textoAss = "\n"+textoAss; for(int i = 2; i <= pageCount; i++) { PdfContentByte pcb = stamper.getUnderContent(i); Paragraph p = new Paragraph(textoAss); p.setFont(fontcabecatable); p.setLeading((float) 10); ColumnText ct = new ColumnText(pcb); ct.setSimpleColumn(positionSignature(position)); ct.addElement(p); ct.go(); } } appearance.setVisibleSignature(positionSignature(position),pagina, null);
    
20.09.2018 / 20:37