I solved the problem by doing the rotation on the image level:

image.setRotation((float) Math.toRadians(pageRotation));

and

image.scaleToFit() or image.scaleAbsolute().

Thanks!

M.

On Mon, Oct 10, 2011 at 9:23 AM, mingqiang yu <[email protected]> wrote:
> Thanks a lot for your help. The rotation works great! But when the
> image is rotated, it is not centered. For example, if I rotate an
> image 90 degrees, it will be aligned to the right. If 180, it will
> aligned to bottom. What will be the best way to make the image aligned
> to the left or centered?
>
> I did see PdfImportedPage has a ALIGN_CENTER attribute. How can I use
> this attribute?
>
> Here are the codes:
>
> Document document2 = new Document();
> PdfReader reader2 = new
> PdfReader(convertImageToPdf("C:\\testData\\Sunset.jpg").toByteArray());
> PdfCopy copy = new PdfCopy(document2, new
> FileOutputStream("C:\\testData\\test1.pdf"));
> document2.open();
> int rotationChange = 90;
> PdfDictionary pageDict = reader.getPageN(1);
> int rotation;
> for (int j = 1; j <= n; j++) {
>    rotation = reader2.getPageRotation(j);
>    pageDict = reader2.getPageN(j);
>    pageDict.put(PdfName.ROTATE, new PdfNumber(rotation + rotationChange));
> }
> PdfImportedPage page = copy.getImportedPage(reader2, 1);
> copy.addPage(page);
> document2.close();
>
> Thanks a lot for your help!
>
> M.
>
> On Fri, Oct 7, 2011 at 2:18 PM, Mark Storer <[email protected]> wrote:
>> Prior to creating the imported page, you can get the page's dictionary
>> and twiddle its rotation.
>>
>> PdfDictionary pageDict = reader.getPageN(1);
>> PdfNumber pageRot = pageDict.getAsNumber(PdfName.ROTATE);
>> PdfNumber newRot = null;
>> if (pageRot == null) {
>>  newRot = new PdfNumber(90);
>> } else {
>>  int currRot = pageRot.intValue();
>>  currRot += 90;
>>  currRot %= 360;
>>  newRot = new PdfNumber(currRot);
>> }
>> pageDict.put(PdfName.ROTATE, newRot);
>>
>> I believe you can do this any time before you call pdfCopy.add(), but
>> I'm not entirely sure.  Safest to do it before creating the
>> PdfImportedPage.
>>
>> --Mark Storer
>>  Senior Software Engineer
>>  Cardiff.com
>>
>> import legalese.Disclaimer;
>> Disclaimer<Cardiff> DisCard = null;
>>
>> Autonomy Corp., an HP Company
>>
>>
>>> -----Original Message-----
>>> From: mingqiang yu [mailto:[email protected]]
>>> Sent: Friday, October 07, 2011 11:07 AM
>>> To: [email protected]
>>> Subject: [iText-questions] Add rotation to a page
>>>
>>> Hi,
>>>
>>> How can I add a rotation value to a PdfImportedPage page? For
>>> example, my rotation value is 90, how can I apply it to my
>>> new PdfImportedPage?
>>>
>>>             ByteArrayOutputStream baos = getImageBaos();
>>>             reader = new PdfReader(baos.toByteArray());
>>>             itextDoc.open();
>>>             PdfImportedPage page =
>>> pdfCopy.getImportedPage(reader, 1); // I'm only getting the 1st page
>>>             pdfCopy.addPage(page);
>>>             baos.close();
>>>             itextDoc.close();
>>>             pdfCopy.close();
>>>
>>> Thanks a lot!
>>>
>>> M.
>>>
>>> --------------------------------------------------------------
>>> ----------------
>>> All of the data generated in your IT infrastructure is
>>> seriously valuable.
>>> Why? It contains a definitive record of application
>>> performance, security threats, fraudulent activity, and more.
>>> Splunk takes this data and makes sense of it. IT sense. And
>>> common sense.
>>> http://p.sf.net/sfu/splunk-d2dcopy2
>>> _______________________________________________
>>> iText-questions mailing list
>>> [email protected]
>>> 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
>>>
>>>
>>
>> ------------------------------------------------------------------------------
>> All of the data generated in your IT infrastructure is seriously valuable.
>> Why? It contains a definitive record of application performance, security
>> threats, fraudulent activity, and more. Splunk takes this data and makes
>> sense of it. IT sense. And common sense.
>> http://p.sf.net/sfu/splunk-d2dcopy2
>> _______________________________________________
>> iText-questions mailing list
>> [email protected]
>> 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
>>
>

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
iText-questions mailing list
[email protected]
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