[EMAIL PROTECTED] wrote:
Hi Bruno,
Thanks for the reply.
Unfortunately, the code you provided doesn't work either.
I just noticed that you contacted me personally for this question,
yet using [iText-questions] in the header. This is not appreciated.
Especially the abuse of [iText-questions] is very misleading.
You should not mail questions to me personally; always post to the list!
I have adapted my code to include your suggestions and tried to set a
very small bleed box.
OK, then you should see that the code I've sent you actually works:
in your original PDF there is only one page boundary:
/MediaBox [0 0 651.969 898.583] in object 3 (page 1)
/MediaBox [0 0 651.969 898.583] in object 21 (page 2)
After running me code, you see that a BleedBox has been added:
Page 1 has now become object 2:
2 0 obj<</Type/Page/Contents 4 0 R/Parent 1 0 R/BleedBox[30 30 250
250]/Resources 5 0 R/MediaBox[0 0 651.969 898.583]>>
endobj
Page 2 has now become object 3:
3 0 obj<</Type/Page/Contents 20 0 R/Parent 1 0 R/BleedBox[30 30 250
250]/Resources 21 0 R/MediaBox[0 0 651.969 898.583]>>
endobj
I have tried two different pdf file.( pdf file enclosed ).
Yep, that's the PDF I tried my code on.
But I see you are using iText 1.00. That version is 4 years old!!!
I don't know if we even had a PdfName.BLEEDBOX constant back then.
Actually I use PdfBox to crop my files and it works fine, but I would
like to do this with Itext because it is faster and also I would like to
do it in one phase.
No problem, but please use a more recent version of iText.
In attachment you find a sample that is tested and works as
expected with the more recent versions of iText.
You included your source code, but it has another error:
final PdfReader pdfReader = new
PdfReader(coverInFile.getAbsolutePath());
final Rectangle cRectangle =
pdfReader.getPageSizeWithRotation(1);
int n = pdfReader.getNumberOfPages();
PdfDictionary pageDict;
for (int i = 1; i <= n; i++) {
pageDict = pdfReader.getPageN(i);
pageDict.put(PdfName.BLEEDBOX, new PdfRectangle(30,
30, 250, 250));
}
final PdfStamper stamper = new PdfStamper(pdfReader, new
FileOutputStream(coverOutFile.getAbsolutePath()));
The following lines are wrong:
final PdfWriter writer = stamper.getWriter();
writer.setPdfVersion(PdfWriter.VERSION_1_4);
You should change the version by using another constructor for
PdfStamper (as demonstrated in the attachment).
HashMap hm = new HashMap();
hm.put("Title", summary.getPrefix() + "00000000.pdf");
stamper.setMoreInfo(hm);
stamper.close();
best regards,
Bruno
import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.pdf.PdfDictionary;
import com.lowagie.text.pdf.PdfName;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfRectangle;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
public class ChangeBleedBox {
public static void main(String[] args) {
try {
PdfReader pdfReader = new PdfReader("original_c.pdf");
int n = pdfReader.getNumberOfPages();
PdfDictionary pageDict;
for (int i = 1; i <= n; i++) {
pageDict = pdfReader.getPageN(i);
pageDict.put(PdfName.BLEEDBOX, new PdfRectangle(30, 30, 250, 250));
}
PdfStamper stamper = new PdfStamper(pdfReader, new FileOutputStream("new_c.pdf"), PdfWriter.VERSION_1_5);
HashMap hm = new HashMap();
hm.put("Title", "00000000.pdf");
stamper.setMoreInfo(hm);
stamper.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/