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

Tile two pages with rotations #440

Closed
wants to merge 2 commits into from
Closed

Conversation

angsch
Copy link
Member

@angsch angsch commented Mar 23, 2021

First proposal towards page tiling #246.

  • Exactly two pages can be glued together vertically.
  • Pages can have any rotation.
  • The functionality aims at being a basic building block to support more complex tiling operations like for instance, horizontal tiling, m x n posters, booklets,... .

Justification of the design decision:
We now have to rotate the content (not just the page orientation). To compensate, we have to shift the content back into the first quadrant of the Cartesian coordinate system. Rotations work recursively. Hence, it is a challenge to tile more than two arbitrarily rotated pages in a single step. Therefore the functionality is limited to two pages and the (hopefully correct) offsets are hardcoded. I consider this easier to maintain than solving equations to get the shifts right. This is not a limitation because it is possible to apply tiling repeatedly.

Known issues:

  • Crop is not supported. Crop for the outside frame of a glued page can be added. The problematic part is the center. Example: We split A -> [A1, A2] and B -> [B1, B2] and want to glue together [A1, B2]. Since cropping only hides the content, we have to find a way to properly chop off A2 and B1.
  • Scaling is not supported.
  • Error handling is missing. It is possible to tile pages whose height does not match.

Input needed:

  • I am not sure how to best handle crops. The ugly solution is to generate a temporary cropped file and use that. It would be nice to have tiling work as an "undo split" operation.
  • What should happen when you apply tiling to a general selection? Tile every second page ("undo split")? Glue everything together (what if not all pages have the same height?)

@dreua
Copy link
Member

dreua commented Mar 23, 2021

I'm confused: Is this about cutting pages to pieces or joining them together? Maybe it's only me but when I hear tiling I think of cutting to pieces (tiles).

@angsch
Copy link
Member Author

angsch commented Mar 23, 2021

It is about putting the content of two pages onto a single page.

@dreua
Copy link
Member

dreua commented Mar 23, 2021

It is about putting the content of two pages onto a single page.

I see, if you think about it this way, tiling makes sense. Maybe "joining" leaves less room for misunderstandings but if I'm the only one confused here we may es well continue using "tiling". Thanks for the clarification!

Unfortunately I don't have time to dive into this new feature, I still have Windows CI and the Annotations bug on my todo list, but it sounds like a great addition to PDF Arranger 👍

@kbengs
Copy link
Member

kbengs commented Mar 26, 2021

Looks like a good start. Using temporary files is not a problem imo. I have no good ideas how to handle crops. (rendering pages to images and tile the images, but that is probably not what we want)

What should happen when you apply tiling to a general selection?

Maybe it could check that an even number of pages are selected and then tile them two by two. Or then it could be like it is now.

@lgtm-com
Copy link

lgtm-com bot commented Apr 4, 2021

This pull request introduces 2 alerts when merging b8b47e2 into 20370a4 - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Variable defined multiple times

@lgtm-com
Copy link

lgtm-com bot commented Apr 4, 2021

This pull request introduces 1 alert when merging 06e0f51 into 20370a4 - view on LGTM.com

new alerts:

  • 1 for Variable defined multiple times

@angsch angsch marked this pull request as ready for review April 4, 2021 15:38
@angsch
Copy link
Member Author

angsch commented Apr 4, 2021

  • Feature is renamed to stitching
  • Only pages with exactly the same height can be stitched
  • Two pages with any crop, scaling or rotation can be stitched, i.e., placed next to each other onto one page.

image

What should happen when you apply tiling to a general selection?

Maybe it could check that an even number of pages are selected and then tile them two by two. Or then it could be like it is now.

Let's make that decision later. The current version only stitches 2 pages.

Sometimes pages that logically should be stitchable are not.

  1. Crop A and save as B.
  2. Load B.
  3. Load A and apply crop.

A and B should have exactly the same dimensions - unfortunately in practice they are not guaranteed to have this. I assume that we have to relax the criterion when pages are stitchable to allow for some rounding error. I consider this a minor point.

Copy link
Member

@kbengs kbengs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one case that does not work as expected. To reproduce:

  • Open a pdf and rotate all pages 90 degrees
  • Export
  • Open the exported file
  • Stick two pages -> it does not look right

Some things I would still do:

  • Delete the "source" pages
  • Insert the new page after last selected page
  • Maybe do a scroll_to_selection() to center the stitched page in window. (because cell size probably change after the operation and the page could be lost out of sight otherwise)

@angsch
Copy link
Member Author

angsch commented Apr 9, 2021

  • Fixed the issue when the loaded document has rotated pages
  • The stitched page replaces the selected two pages at the right spot

I am not happy with the integration into the undo manager. To restore the original two pages, you have to undo twice. Both the deletion of the original pages and the pageadder are a single action that is tracked. I don't know how exactly the undo manager works and currently do not see an easy way out, do you?

@dreua
Copy link
Member

dreua commented Apr 9, 2021

@jeromerobert wrote the undo manager. I haven't looked into this specific problem but it sounds doable to me. Maybe understanding and modifying the undo manager is necessary.

* Pages with rotation rotate the content and move the content to
  the final position.
* Pages with a mediabox [x1, y1, x2, y2] where x1, y1 > 0 create a
  temporary page such that the mediabox is [0, 0, width, height]. Crop
  creates such pages. This facilitates the side-by-side placement of
  pages because rotations are around (0,0).
* Without a tmp page, it is not possible to stitch pages where the
  glue side is cropped. Ex: Crop A  l: 0, r: 50%, crop B l: 50%, r:0,
  stitch [A | B].
* Pages with scaling create a temporary page
@angsch
Copy link
Member Author

angsch commented Apr 9, 2021

Should have rebased earlier - would not have encountered my problem with the undo manager. Great work again, kbengs

@kbengs
Copy link
Member

kbengs commented Apr 10, 2021

Nice. Found a few more things:

  • If two pages that are not adjacent are stitched together the resulted page will not be selected
  • Scroll_to_selection does not work for me. It does work with GObject.timeout_add(50, self.scroll_to_selection) (the function would need to be improved a bit so that it would work without the timeout)
  • Annotations seems to be removed. That is maybe ok, but are they removed or just moved to a side, and could become visible sometimes?
  • If the Linux Format page in # 443 is stitched the invisible margins will become visible
  • I tried to do the stitch action repeatedly. 4 pages worked good, but with 4+4 pages it did not look right any more. (see pictures)

4 pages stitched is ok:
before1

But not 4+4:
after2

@Davexx
Copy link

Davexx commented Sep 19, 2022

In case anyone is interested, the Fujitsu Scan Snap Organizer Viewer has a stitch feature they call Merge, with "Merge Vertically" and "Merge Horizontally" as the two options. One has to select the two pages and right-click to see it in the context menu.
If the pages don't match, an error window pops up and says the paper size or page orientation do not match, prompting the user to check the size or orientation and try again.
If this feature does get worked on, I would suggest a warning message like the one mentioned above, but then ask the user if they would like to 1.) scale or crop the left page to match the right page, or 2.) scale or crop the right page to match the left page. I think this would make it way more convenient a feature.

I also support the idea of some sort of bulk stitching method, where a user could, say, select a contiguous group of even amount of pages and pdfarranger would execute the stitches on each pair from left to right.

I realize this is not easy to code, but it sure would make for a powerful feature and a nice compliment to the "Split Pages" feature.
Thanks for considering.

@DegrangeM
Copy link

DegrangeM commented Jan 2, 2023

Hi, any progress on this ? I would love this feature <3 Thanks.

Being able to put two A4 paper into one A4 paper (by scaling and rotating) would be really usefull.
I saw the PR changed to stitching which make what I need a little harder to do, but stitching is usefull too.

@kbengs
Copy link
Member

kbengs commented Apr 26, 2023

This was implemented in #847

@kbengs kbengs closed this Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants