1)
-I read the pdf using PdfReader,
- import the first page (i omit to say that : i have only one simple page in the original pdf with no bookmarks etc ...)
2) I write text and image on Graphics2D
4) I close everything :)
Here is the code where I initialize the objects ( step 1)
private class PdfDocumentContainer {
public ByteArrayOutputStream baos;
public Document doc;
public PdfImportedPage page;
public PdfContentByte contentByte;
public Graphics2D g2d;
PdfDocumentContainer() {
baos = new ByteArrayOutputStream();
}
}
private PdfDocumentContainer initPdf(String pdfFile)
throws ProcessingException {
logger.fine("initializing pdf with file :" + pdfFile);
PdfDocumentContainer result = new PdfDocumentContainer();
PdfReader reader = null;
try {
// we create a reader for a certain document
reader = new PdfReader(pdfFile);
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
// we retrieve the size of the first page
Rectangle psize = reader.getPageSize(1);
float width = psize.width();
float height = psize.height();
// step 1: creation of a document-object
Document document = new Document(psize, 50, 50, 50, 50);
result.doc = document;
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, result.baos);
document.open();
// step 4: we add content
PdfContentByte cb = writer.getDirectContent();
result.contentByte = cb;
result.g2d = cb.createGraphics(width, height, mapper);
PdfImportedPage page1 = writer.getImportedPage(reader, 1);
result.page = page1;
return result;
} catch (IOException ioe) {
} catch (DocumentException de) {
}
}
Le ven 03/12/2004 à 12:46, Paulo Soares a écrit :
Using PdfStamper?
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Guillaume Allée
Sent: Friday, December 03, 2004 10:36 AM
To: [EMAIL PROTECTED]
Subject: [iText-questions] Rotate a existing pdf document 90 deg
Hi,
I search for posts on how to do this but I did not find anything that fits my problem.
Here it is :
1) I read a pdf file (that can be anything).
2) I add text and image on it using the itext library :)
3) I want to rotate the whole thing( the original file + text + image) 90 degrees.
4) I save it
Do you know how i can perform the step 3 ?
Thanks
-- Allée Guillaume Senior Development Engineer ATCHIK 8, Port Saint Sauveur 31000 Toulouse France E-mail: [EMAIL PROTECTED] Web: http://www.atchik.com tel: +33 5 34 31 77 22 fax: +33 5 34 31 70 71 Mob: +33 6 75 08 52 38
-- Allée Guillaume Senior Development Engineer ATCHIK 8, Port Saint Sauveur 31000 Toulouse France E-mail: [EMAIL PROTECTED] Web: http://www.atchik.com tel: +33 5 34 31 77 22 fax: +33 5 34 31 70 71 Mob: +33 6 75 08 52 38 |
