0
votes

Let me give you an overview of my project first. I have a pdf which I need to convert into images(One image for one page) using PDFBox API and write all those images onto a new pdf using PDFBox API itself. Basically, converting a pdf into a pdf, which we refer to as PDF Transcoding.

Now, I have some cases wherein eveyrthing goes fine, i.e. the transcoded pdf exactly matches the original pdf contents, but just 1/10 cases are like, the dimensions of transcoded pdf is getting swapped somehow. For example, original pdf- 8.2 x 11.2 transcoded pdf- 11.2 x 8.2. In short, height is getting swapped with width. I don't know why this API is behaving differently for different files. If anyone could answer the same?

Thanks in advance, Vaibhav

1
A PDF page object can be rotated by a multiple of 90°. Maybe one of the used software packages respects this rotation while the other one doesn't. - mkl
Thanks mkl for getting back. But how do I recognize at the first place then, that what object will be rotated and what not, so that I can deliver the outputs equably in every condition? - Vaibhav Sawalkar
As you are using PDFBox, you can query the rotation of a PDPage page using page.findRotation(). In essence it returns the value of the Rotate key of the page or (if not found there) its ancestors in the page tree. - mkl
Thanks mkl. I have already done that and it worked! Thanks again! :) - Vaibhav Sawalkar
Ok. I'll make that an answer then. - mkl

1 Answers

2
votes

(Summarizing the results of the dialogue in the comments to the original question)

Each page of a PDF has a rotation property which can indicate a rotation of the otherwise defined page coordinates, confer the PDF specification ISO 32000-1:

Rotate integer (Optional; inheritable) The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. Default value: 0.

(Table 30 Entries in a page object on page 78)

E.g., a page by its media box being defined to have an A4 portrait format may still have to be displayed as an A4 landscape page.

In your case one of the used software packages seems to respect this rotation while the other one doesn't.

As you are using PDFBox, you can query the rotation of a PDPage page using

int rotation = page.findRotation();

In essence it returns the value of the Rotate key of the page or (if not found there) its ancestors in the page tree.