-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Alternative to add_transformation translate #1426
Comments
you should have a look at #558 (comment) |
Well the #558 just mentions the the code I've already listed. |
Maybe this can explain it a bit better:
|
Ok I solved my problem. My solution was to keep changing the translate(tx, ty) in each loop.
After that I move the trimbox because that's the only thing that does not get moved with the translate() automatically. |
For some reason it breaks if i want to use different page numbers to impose. |
just note that the add_transformation will modify page_box so each transformation needs to be relative to previous one |
can you please clarify |
Yes so im placing the same pdf (a businesscard) on a bigger pdf. But if I mix the pages (not the same page of the pdf), the pages are then moved way off like there's something not resetting right. |
|
can you provide your failing please blank page |
Here is the pdf files I use: The code I posted above should work and create a 4column, 4 row pdf. If you change the following code: to this code:
Id should now be messed up. but when you look in outline mode in adobe illustrator you can se it will place the correct pdf pages, but the placement (mediabox) is wrong. |
@MartinThoma / @MasterOdin, |
Huh, interesting. I don't understand yet why the issue occurs. It sounds like a bug and thus it would be preferable to fix it. But re-introducing the old (working) functions as an intermediate solution would be OK to me. We would need to document that issue for the new functions though |
Any news on this problem ? |
lost in the fifo... will come back on it this week-end |
Still no update? |
Could we please reintroduce the "mergeRotatedTranslatedPage" class and make it take normal cords and not the tx, ty. The current functionality breaks when I try to rotate or try mix page numbers. |
It's hard for me to understand the issue as the information is scattered in this thread. Could you maybe adjust the first comment in this ticket to contain all the information? A great bug ticket follows this pattern:
I'm open to a PR re-introducing |
@MartinThoma |
@felle9900,
still some clean-up (mypy) and testing to be done |
I've just upgraded pypdf to version 3.3.0 to test that code. Did I miss anything ? ( I used my own pdf files) |
you have to copy the modifed files from the PR |
Hmm can't se a ez way to download the 9 files. I'm not gonna go thru it manually so I think Ill just wait for it to be implemented. |
@felle9900 It is implemented in #1567 . We just need somebody to check if it worked as expected. You can do it like this:
|
I tried to follow along but the line:
|
Uh, right, you need the https URL instead of the git one |
I did the venv to clone the PyPDF2 in the directory (should it not be pypdf btw?). Now the code don't recognize "pypdf" so i changed them to "PyPDF2", but I then get a error that PyPDF2 does not have a method called "merge_transformed_page" |
Ok now I got it working - why is the placed pdf pulled in cropped to the trim box? shouldn't it import the whole media box size? |
There is a problem when I'm placing several impositions (businesscard pdf) on my big sheet-pdf. |
I dislike the idea to add extra parameters: The best for me is to adjust/modify the boxes in the source page before inserting. |
I've successfully got this result (requires latest fix): the code import pypdf
r = PdfReader("visitcard.pdf")
w = pypdf.PdfWriter()
w.add_blank_page(pypdf.PaperSize.A6.width, pypdf.PaperSize.A6.height)
for x in range(4):
for y in range(7):
w.pages[0].merge_translated_page(
r.pages[0],
x * r.pages[0].trimbox[2],
y * r.pages[0].trimbox[3],
True,
True,
)
w.write("tt.pdf") the output |
Ok this is pretty cool, Could I use 450 x 320 mm instead of "A6" somehow ? I managed to crop my pdf the way i like (trimbox+5mm) = It displays correctly I also managed to test that it will place different page numbers from the "visitcard" - tested by using randint(0,1) But there is a big bug I can't get past: If you swap out your "visitcard.pdf" with my card |
At the current state you can't translate less than the mediabox. Maybe that is hardcoded somewhere? |
Not really as all depends on the |
Ok cool I got it, thanks. What about the translate bug ? |
Take look on this code, there's some weird stuff going on. Only the first imposition is cropped correctly (bottom left)
|
In the test code I've produced, I've set the expand to true : the boxes are expanded : I've used A6 to start with but the final size is far much more bigger |
I'm confused about your code : Why are you change the trimbox every cycle : you should modify it once and the box is applied. However reviewing the code I agree that there is something odd (even in the old code) : the cropping is done based on the trim box instead of the crop box (which define the clipping for display and printing) |
I'm sorry, I don't understand the question @pubpub-zz . What do you want to know? |
This behavior is often confusing for people, but I'm uncertain about the best way to improve it. Maybe adding a parameter A method |
Currently |
this my be very tough to implement...😕 |
The reson im adjusting the trimbox on each cycle is because that can only be done to a specific page on the pdf. That page can be any pagenr at every cycle. But I was maybe thinking of doing a seperate loop of cropping the businesscard pages so all of the boxes (mediabox/tribox/cropbox) are removed - then the script might work because it just have to place those pages right next to each other. Im gonna go test that out. |
I did at test by using a cropped file (cropbox = (trimbox + 5 mm)) - file was cropped in Acrobat. Works like a charm, se the pdf. I remember I did try this a long time ago but I ran into a problem because the old pypdf2 would not respect the cropping of the pdf file it had made itself (wierd). Im going to test that part now. |
It worked :) :) :)
|
The only thing I would need is being able to place this centered on a 420 x 320 pdf. |
@MartinThoma |
@MartinThoma what do you think about using CropBox instead of TrimBox ? |
@pubpub-zz I guess you are referring to this piece: rect = page2.trimbox
page2content.operations.insert(
0,
(
map(
FloatObject,
[
rect.left,
rect.bottom,
rect.width,
rect.height,
],
),
"re",
),
) It's similar to our discussion in #879 , right? What does that part of the code actually do? |
From the description I tend to agree: |
Several issues could have been avoided if the example in this PR existed before, e.g. #1630, #1426 Co-authored-by: Louis <[email protected]>
I'm trying to update a older pypdf2 program I've made that can step and repeat several pdf-files on a bigger pdf page.
But the current method seams to work on a bit primitive way:
Keeps translating 50 pt between every pdf im placing. Thats not what Im looking for :)
Any way of doing it the old way with dedicated x1, y,1, x2, y2 values instead?
I used to use the mergeRotatedTranslatedPage()
The text was updated successfully, but these errors were encountered: