java - PageSize of PDF always the same between landscape and portrait with itextpdf -


I have a PDFReader that includes some pages and other images in landscape mode.

I need it to treat them differently ... However, if I call GetOrientation or GetPageSize, the value is always the same (595 for paging and 0 for orientation) .

A page in the scenario?

I have tried to find other ways to get page width / orientation but nothing has worked.

Here is my code:

 for  (int i = 0; i & lt; pdfreader.getNumberOfPages (); i ++) {document = PdfStamper.getOverContent (I) .getPdfDocument (); Document.getPageSize () getWidth // it will always be the same)  

Thanks!

getPageSize () and getPageSizeWithRotation () There are two feature methods named. Let's take a look at an example:

  PDF Reader Reader = New PDF Reader ("src / main / resources / pages.pdf"); Show (reader.getPageSize (1)); Show (reader.getPageSize (3)); Show (reader.getPageSizeWithRotation (3)); Show (reader.getPageSize (4)); Show (reader.getPageSizeWithRotation (4));  

In this example, the show () method looks like this:

  public static zero show (rectangle rect) { System.out.print ("llx:"); System.out.print (rect.getLeft ()); System.out.print (", lly:"); System.out.print (rect.getBottom ()); System.out.print (", urx:"); System.out.print (rect.getRight ()); System.out.print (", lly:"); System.out.print (rect.getTop ()); System.out.print (", rotation:"); Println (rect.getRotation ()); }  

This output is:

  llx: 0.0, lly: 0.0, urx: 595.0, lly: 842.0, rotation: 0lx: 0.0, Lly : 0.0, urx: 595.0, lly: 842.0, rotation: 0 locale: 0.0, lily: 0.0, urx: 842.0, lily: 595.0, rotation: 90lx: 0.0, lily: 0.0, urx: 842.0, lily: 595.0, rotation : 0 LX: 0.0, Lily: 0.0, URX: 842.0, Lilly: 595.0, Rotation: 0  

Page 3 (See sample 3.8 in code 4) An A4 page is Page 1, But this scenario is oriented in the / mediabox entry for the first page [0 595 842] . , And why is that getPageSize () the same result.

The page is in landscape, because the page dictionary is set to 90 in the \ rotate entry. The possible value of this entry is 0 (the default value if the entry is missing), 90 , 180 and 270 .

getPageSizeWithRotation () method keeps this value in mind. It swaps the width and height so that you stay aware of the difference. It also gives you the value of the entry / rotate . Page 4 also has a landscape orientation, but in this case, the rotation to / mediabox entry in this case / mediabox is the value of .

[0 842 595] and if there is any / rotate entry, then its value is 0 . .

This indicates that the output of getPageSizeWithRotation () method is similar to the output of getPageSize () method.

When I read your question, then I see that you are looking for rotation. This can be done with the getRotation () method.

Note: This text has been copied from my book (book is under construction, you can download the first chapter for free). Code sample can be found.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -