Hi all,
         I'm working on the generation of few reports with iText.
I'm completely stuck trying to understand what's going on and I have no
more ideas on how to debug it.
Basically I produce a series of PDFs (1 or more pages) and afterwards I
want to add a watermark.

It seems working good if I use the getUnderContent from the PDFStamper, but
this correctly put my watermark in the background.
I want my text (or image) in the top layer, so I tried to use
getOverContent.

And here the weird behaviour: when I try to rotate it (text) the rotation
is correct for few pages and is 90 degrees wrong for others!

I cannot understand where's the issue here as I've checked rotation for all
the pages and is 90 degrees for all of them.

    private void addDraftWatermark(String filename) throws IOException,
DocumentException {
        File subClientFolder = new File(filename);

        if (subClientFolder.exists() && subClientFolder.list().length > 0) {
            for (File folder : subClientFolder.listFiles()) {
                File[] listPDFs = folder.listFiles();
                for (File pdf : listPDFs) {
                    String realFilename = pdf.getAbsolutePath();
                    PdfReader reader = new PdfReader(realFilename);
                    String draftFilePath = pdf.getParent() + "\\draft - " +
pdf.getName();
                    PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream(draftFilePath));

//                    Properties properties = new Properties();
//
 
properties.load(AbstractReport.class.getResourceAsStream("/kobalt/sax/reports/properties/javareports.properties"));
//                    String temp = (String)
properties.get("imagelocationdev");
//                    Image img = Image.getInstance((String)
properties.get("imagelocationdev") + "draftwatermark.png");
//                    img.setAbsolutePosition(150, 60);

                    PdfContentByte wtmk;
                    BaseFont bf =
BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250,
BaseFont.NOT_EMBEDDED);
                    int total = reader.getNumberOfPages() + 1;
                    for (int i = 1; i < total; i++) {
                        wtmk = stamper.getOverContent(i);
                        //image
//                        wtmk.addImage(img);
                        //text
//                        PdfGState gState = new PdfGState();
//                        gState.setFillOpacity(0.4f);
//                        wtmk.setGState(gState);

                        wtmk.beginText();
                        wtmk.setFontAndSize(bf, 200);
                        wtmk.setRGBColorFill(0xC8, 0xB4, 0xB4); // rotation
                        wtmk.showTextAligned(PdfContentByte.ALIGN_LEFT,
"DRAFT", 140, 90, 25);

                        // test
                        int rotation = reader.getPageRotation(1);
                        Rectangle box =
wtmk.getPdfWriter().getBoxSize("media");

                        wtmk.endText();

                    }
                    stamper.close();
                    reader.close();
                    pdf.delete();

                    File draft = new File(draftFilePath);
                    draft.renameTo(new File(realFilename));
                }
            }
        }
    }

I'll really appreciate any suggestion.

Thanks,
Diego
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to