The code as it is processes correctly the crop box. You are probably looking
at something else. Why don't you create a document with iText or Acrobat
with a crop box with some marking around the limits to see there's really a
margin problem? Or use the file http://www.jahn.org/pdf3/cmyk.pdf that has
crop marks to see what happens.

Best Regards,
Paulo Soares

----- Original Message -----
From: "Waymon Ho" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 11, 2002 0:37
Subject: [iText-questions] margin problem



Hi Paulo and all,

I study the code that Paulo send me about a week ago about the crop box
effect.  And I still having the extra margin effect on the copied
document.
I still not really sure if it's the crop box that causing the problem.

Here is the problem that I��m having.  I'm writing a program that copy
the
exist PDF file into a new PDF file and add a text on top of it.  And the
new
PDF file has extra margin than the original one (about twice as big).
And I
test it with different pdf file, and I notice for some pdf file, it��s
ok,
and for other is not.  So, I��m not sure why and how I should fix it.
Below
is my code, please help me out if anyone has any idea.

P.S.  The PDF file that I used to test my program is JRUN spec.  That's
the
file that gave me extra margin.  I create couple PDF file myself, those
copy
was copy good with exact same margin.  Don't know what's the different.

Thanks once again,

Waymon

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

public class Textwatermark {


    public static void main(String[] args) {

        System.out.println("Chapter 1 example 12: reading an existing
PDF
file");

        try {
            // we create a reader for a certain document
            PdfReader reader = new PdfReader("M:\\programming.pdf");
            // we retrieve the total number of pages
            int n = reader.getNumberOfPages();
            // we retrieve the size of the first page
            Rectangle psize = reader.getCropBox(1);
            float width = psize.width();
            float height = psize.height();
            Rectangle media = new Rectangle(width,height);

            // step 1: creation of a document-object
            Document document = new Document(media, 0, 0, 0, 0);
            // step 2: we create a writer that listens to the document
            PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("M:\\trytry.pdf"));

            // step 3: we open the document

            document.open();
            PdfContentByte cb = writer.getDirectContent();
PdfTemplate template = cb.createTemplate(width, height);
            // setup a template that have "pre-release" on it
            template.beginText();
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN ,
BaseFont.CP1257, BaseFont.EMBEDDED);
            template.setFontAndSize(bf,48);
            template.setTextMatrix(100,35);
            template.setRGBColorFill(0xFF, 0x00, 0x00);

            template.showText("Pre-Release");
            template.endText();

            int i = 0;
            int p = 0;
while (i < n) {
                document.newPage();
                p++;
                i++;
                PdfImportedPage page1 = writer.getImportedPage(reader,
i);
                page1.setBoundingBox(psize);
                //add the existing template
                cb.addTemplate(page1, 1, 0, 0, 1, -psize.left(),
-psize.bottom());
System.err.println("processed page " + i);

                cb.beginText();
                cb.endText();

            }
document.close();
            System.out.println("Done");
        }
        catch (Exception de) {
            de.printStackTrace();
        }
    }

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Two, two, TWO treats in one.
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
PC Mods, Computing goodies, cases & more
http://thinkgeek.com/sf
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to