Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

booklet/nup: handle existing page rotation #349

Closed
adamgreenhall opened this issue Jun 30, 2021 · 6 comments
Closed

booklet/nup: handle existing page rotation #349

adamgreenhall opened this issue Jun 30, 2021 · 6 comments
Assignees
Labels

Comments

@adamgreenhall
Copy link
Contributor

adamgreenhall commented Jun 30, 2021

When reading a pdf that has been rotated (either using pdfcpu or some other tool), PageDims (media box?) within pdfcpu doesn't seem to know about the rotation.

Example:

pdfcpu info test.pdf | grep "Page size"
           Page size: 612.00 x 396.00 points
pdfcpu rotate test.pdf 90 test-rotated.pdf
pdfcpu info test-rotated.pdf | grep "Page size"
           Page size: 612.00 x 396.00 points              <---- expecting 396.00 x 612.00 points
@hhrutter
Copy link
Collaborator

It is not that simple unfortunately.

pdfcpu info test.pdf returns a list of used page dimensions in the file.
If you have a file with 10 pages and the cover page has different dimensions than the rest you get
dumped out 2 page dimensions. Since this info is consolidated it cannot account for the page rotation which
applies to each and every page individually and even more the rotation is an inherited page attribute.

pdfcpu info -pages 1- test.pdf also returns the page boundaries for all pages which includes the dimensions,
but not the rotation in effect.

What's your specific use case?
There's room for improvement without doubt.

@adamgreenhall
Copy link
Contributor Author

My use case is that I have a pdf that I'm trying to run through pdfcpu booklet, but it's rotated 90deg. As you might imagine, this causes problems. Trying to fix it by pdfcpu rotate or rotate in macos preview doesn't work.

Makes sense about the different pages having different dimensions/rotation.

@hhrutter
Copy link
Collaborator

I see. I need to go back and double check but I thought booklet was taking care of page rotation.
Any chance you can get me a sample?

@adamgreenhall
Copy link
Contributor Author

So, I've been working on adding a few more booklet layouts for different orientations and bindings and which booklet layout you use depends on the page orientation (portrait or landscape) and the binding (long- or short-edge) you want. Like this:
Screen Shot 2021-06-30 at 11 50 11 AM

So being able to correctly detect the real page orientation from the rotation would be really handy.

I'll send you an example pdf on slack.

@hhrutter hhrutter changed the title handle page rotation when reading pdf booklet: handle page rotation Jun 30, 2021
@hhrutter hhrutter self-assigned this Jun 30, 2021
@hhrutter hhrutter added bug and removed investigate labels Jul 9, 2021
@hhrutter hhrutter changed the title booklet: handle page rotation booklet/nup: handle existing page rotation Jul 9, 2021
@hhrutter
Copy link
Collaborator

hhrutter commented Jul 9, 2021

OK, so any existing rotation value != 0 for input file pages needs to be taken into account during the rendering phase on the new page like it is done for stamping.

Unfortunately I was wrong. 😞 I thought that's already in there in: nup.go
Once it works for nup it will also work for booklets, since that command is just a variation of nup.

The general idea is to internalize the page rotation and carry it over into the content stream via a transform matrix.
See pdfcpu/stamp.go and the handling of wm.pageRot.

Since this is quite tricky it will not be part of the upcoming release that I am about to push.
Again 😞

@hhrutter
Copy link
Collaborator

This has been addressed with the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants