Hallo,
i have a pdf source document with an image in it. Itext is generate a new
PDF, but it turns the image from upright to accross and i don´t know why.
And i didn´t work a lot with itext and got a java code, that is doing this.
Here the function:
public byte[] getSplitCell(int x, int y, int width, int height, int dpi,
boolean getUseWithIM) throws Exception {
int pageNumber = 1;
Rectangle docsize = pdfReader.getPageSize(pageNumber);
Rectangle tmp1 = pdfReader.getPageSizeWithRotation(pageNumber);
float h = (72.0f*height)/(dpi);
float w = (72.0f*width)/(dpi);
float x1 = (72.0f*x)/(dpi);
float y1 = (72.0f*y)/(dpi);
if (x1 + w > tmp1.getWidth()) {
w = tmp1.getWidth() - x1;
}
if (y1 + h > tmp1.getHeight()) {
h = tmp1.getHeight() - y1;
}
if (w == tmp1.getWidth() && h == tmp1.getHeight()) {
if (dpi == 50 && !getUseWithIM)
return pdfData;
}
if (w <= 0 || h <= 0) {
throw new IllegalArgumentException("x or y parameters are out of
the document dimensions. The document dimension is " + tmp1.getWidth() + "x"
+ tmp1.getHeight() + " for dpi " + dpi);
}
docsize.setLeft(0);
docsize.setBottom(0);
docsize.setRight(w);
docsize.setTop(h);
docsize.setBorderWidth(-1);
Document document = new Document(docsize);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfImportedPage page;
document.setPageSize(tmp1);
document.newPage();
page = writer.getImportedPage(pdfReader, pageNumber);
cb.addTemplate(page, 1, 0, 0, 1, -x1, -tmp1.getHeight() + y1 + h);
document.close();
baos.close();
return baos.toByteArray();
}
This function works fine with hundreds of PDF´s. But one PDF (210 x 297 mm)
is turning the image. The size will be ok, but in result the image ist
turned and about the half of it is dissappearing behind the right border.
In pdfReader is the source PDF. Perhaps somebody will the the hint in one
view.
Thank you for any help.
Jochen
--
View this message in context:
http://www.nabble.com/Newbie-has-problems-with-page-layout-tp19972995p19972995.html
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php