PDF content plus size scaling #3099
-
Hello, I am planning to scale a pdf page and content to specified page height and width, Also, Is it possible to reset he coordinates of pdf, Since for some pdf the origin is in different location. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 24 replies
-
You can use method import fitz
doc = fitz.open() # new PDF
src = fitz.open("input.pdf")
for srcpage in src:
page = doc.new_page(width=w, height=h)
page.show_page_pdf_page(page.rect, src, srcpage.number)
doc.ez_save("output.pdf") The output pdf will show the original, scaled pages.
|
Beta Was this translation helpful? Give feedback.
-
I am facing issue for note 1
Source page height width and the input provided by us are not matched so
not working properly in that case how can we fixed .
…On Fri, Jan 26, 2024 at 19:24 Jorj X. McKie ***@***.***> wrote:
You can use method Page.show_pdf_page() for this.
Assume w, h being the desired page width and height:
import fitzdoc = fitz.open() # new PDFsrc = fitz.open("input.pdf")
for srcpage in src:
page = doc.new_page(width=w, height=h)
page.show_page_pdf_page(page.rect, src, srcpage.number)
doc.ez_save("output.pdf")
The output pdf will show the original, scaled pages.
Please note:
1. If w, h are not the same aspect ratio (w/h != src-width / src-height),
there will be empty stripes on the output pages.
2. If input pages are rotated, the code above will need some
modification.
3. Links and annotations or fields will not be included in this type
of copy. For links at least, there are ways to rescue them.
—
Reply to this email directly, view it on GitHub
<#3099 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKJ2AQFOPWQJOXAU56S3RFTYQN747AVCNFSM6AAAAABCL2H4UWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DENJVGMZTM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Could you give me some examples,
So I would be more clear on this .
Thanks
…On Fri, Jan 26, 2024 at 20:43 Jorj X. McKie ***@***.***> wrote:
It cannot be fixed if you insist on a fixed, file-wide w, h.
You must decide about another approach, like
- accept source page rectangle's aspect ratio but divide each edge by
2 or whatever
- accept that the source page is shown distorted (stretched or
shrinked in one dimension)
—
Reply to this email directly, view it on GitHub
<#3099 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKJ2AQHQYN47UN55XBTATSTYQOJE7AVCNFSM6AAAAABCL2H4UWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DENJWGEYTO>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Can you let me have an example PDF and tell me what exactly you want to achieve with it please? |
Beta Was this translation helpful? Give feedback.
-
As per my understanding target page have markups (funky type annotations)
from bluebeam software , even though I tried to import manually to the file
that we have just generated that annotation are moved in different position
.Any reason for that ?
As per I understand when we use show_pdf_page it must just replace the
target page content . How it is related to the content .
…On Mon, Jan 29, 2024 at 2:14 Jorj X. McKie ***@***.***> wrote:
By design, '.show_pdf_page()` *cannot* copy annotations or fields.
The main reason being, that the source page is converted to a non-page
object, a so-called "Form XObject". This PDF object type cannot have
annotations, links or fields - and nothing can be done about this.
With one possible part exception: hyper-links. The script above is
basically equivalent to applying a suitably computed Matrix. So
hyper-links that point to *external* resources could be re-created on the
target page, IAW GoTo, and Named links will never work.
If you find a way to also recreate annotation on the target, you must of
course apply the appropriate scaling, complete transformation. For example,
if the source page rectangle is srect and that of the (scaled) target is
trect then you can make a matrix mat = srect.torect(trect). Then the
rectangle of an annotation on the target page is annot.rect * mat.
—
Reply to this email directly, view it on GitHub
<#3099 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKJ2AQA3GMPILWXL6HAGSDLYQ2BPDAVCNFSM6AAAAABCL2H4UWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DENZTGIZDS>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
If we apply transformation for the annotation for funky type that are not
supported by this library , May be it will loose its attribute while doing
transformation.
Any idea to control this ?
On Mon, Jan 29, 2024 at 2:35 Purna Pachhai ***@***.***>
wrote:
… As per my understanding target page have markups (funky type annotations)
from bluebeam software , even though I tried to import manually to the file
that we have just generated that annotation are moved in different position
.Any reason for that ?
As per I understand when we use show_pdf_page it must just replace the
target page content . How it is related to the content .
On Mon, Jan 29, 2024 at 2:14 Jorj X. McKie ***@***.***>
wrote:
> By design, '.show_pdf_page()` *cannot* copy annotations or fields.
> The main reason being, that the source page is converted to a non-page
> object, a so-called "Form XObject". This PDF object type cannot have
> annotations, links or fields - and nothing can be done about this.
>
> With one possible part exception: hyper-links. The script above is
> basically equivalent to applying a suitably computed Matrix. So
> hyper-links that point to *external* resources could be re-created on
> the target page, IAW GoTo, and Named links will never work.
>
> If you find a way to also recreate annotation on the target, you must of
> course apply the appropriate scaling, complete transformation. For example,
> if the source page rectangle is srect and that of the (scaled) target is
> trect then you can make a matrix mat = srect.torect(trect). Then the
> rectangle of an annotation on the target page is annot.rect * mat.
>
> —
> Reply to this email directly, view it on GitHub
> <#3099 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AKJ2AQA3GMPILWXL6HAGSDLYQ2BPDAVCNFSM6AAAAABCL2H4UWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DENZTGIZDS>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
When I checked source as well as target page what I found is , In source
page the cordinates top left , bottom left, top right and bottom right are
not same as target page . As Target page contains markups ,
When I try to replace target page with source page May be due to
coordinates it replaces the position of markups.
Although the orientation seems same between source and target page and
width height is also same between two pages the top left coordinates
starting are different .
Target page coordinates is (0,0)
Source page coordinates is (0,something)
So, if I can reset the coordinates of source page keeping page orientation
same as target page it can be fixed .
So, I need to know if it’s possible to reset pdf coordinates keeping
orientation same and save it . And just replace to target page .
Can you help me on this ?
…On Tue, Jan 30, 2024 at 23:37 Jorj X. McKie ***@***.***> wrote:
I thought we had been talking about ways to let *source* annotations
survive???
—
Reply to this email directly, view it on GitHub
<#3099 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKJ2AQDQAUQHTL6MD3MTL3LYREAT7AVCNFSM6AAAAABCL2H4UWVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DGMBWGYYTC>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I am closing this discussion for now because my issue is solved for now. |
Beta Was this translation helpful? Give feedback.
Ok, good! Alright then.
I am calling the scale factor
scale
. After the following code snippet, pages are resized, have rotation 0 and CropBox = MediaBox.