logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
oberon232  
#1 Posted : Sunday, February 24, 2019 12:29:35 AM(UTC)
oberon232

Rank: Newbie

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 6
United States
Location: FL

Thanks: 1 times
How do you resize and existing page in a pdf?
Specifically, I want to add space on the top of the page so I can insert a text object without covering over any of the existing page.
Paul Rayman  
#2 Posted : Sunday, February 24, 2019 4:51:25 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 724

Thanks: 1 times
Was thanked: 87 time(s) in 86 post(s)
Hi,

Seems you need to change one or more of the following boundaries

MediaBox - (Required; inheritable) A rectangle (see Section 3.8.4, “Rectangles”), ex
pressed in default user space units, defining the boundaries of the physical
medium on which the page is intended to be displayed or printed (see
Section 10.10.1, “Page Boundaries”).

CropBox - (Optional; inheritable) A rectangle, expressed in default user space units,
defining the visible region of default user space. When the page is dis
played or printed, its contents are to be clipped (cropped) to this rectangle
and then imposed on the output medium in some implementation
defined manner (see Section 10.10.1, “Page Boundaries”). Default value:
the value of MediaBox.

BleedBox - (Optional; PDF 1.3) A rectangle, expressed in default user space units, de
fining the region to which the contents of the page should be clipped
when output in a production environment (see Section 10.10.1, “Page
Boundaries”). Default value: the value of CropBox.

TrimBox - (Optional; PDF 1.3) A rectangle, expressed in default user space units, de
fining the intended dimensions of the finished page after trimming (see
Section 10.10.1, “Page Boundaries”). Default value: the value of CropBox.

ArtBox - (Optional; PDF 1.3) A rectangle, expressed in default user space units, de
fining the extent of the page’s meaningful content (including potential
white space) as intended by the page’s creator (see Section 10.10.1, “Page
Boundaries”). Default value: the value of CropBox.

Page boundaries

Here is an example how to get these boxes
https://forum.patagames....-and-trimbox-of-the-Page

Changing these properties is the opposite. Something like this

Code:
var array = PdfTypeArray.Create();
array.Add(PdfTypeNumber.Create(left));
array.Add(PdfTypeNumber.Create(bottom));
array.Add(PdfTypeNumber.Create(right));
array.Add(PdfTypeNumber.Create(top));
pageDict["CropBox"] = array;

Edited by user Sunday, February 24, 2019 4:53:59 AM(UTC)  | Reason: Not specified

oberon232  
#3 Posted : Sunday, February 24, 2019 8:34:45 AM(UTC)
oberon232

Rank: Newbie

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 6
United States
Location: FL

Thanks: 1 times
Modifying the crop and media boxes in the page's dictionary doesn't appear to affect how the viewer displays the page, and the PdfViewer1.CurrentPage.Height remains the same after the change.
Is there a step I'm missing to apply the change?

Here's my code (it's in VB.net)
Code:
Private Sub btnConfidential_Click(sender As Object, e As EventArgs) Handles btnConfidential.Click
        Dim doc As PdfDocument = PdfViewer1.Document
        Dim pageDict As PdfTypeDictionary = doc.Pages(PdfViewer1.CurrentIndex).Dictionary

        Dim cropBox As PdfTypeArray = pageDict("CropBox").As(Of PdfTypeArray)
        Dim mediaBox As PdfTypeArray = pageDict("MediaBox").As(Of PdfTypeArray)

        cropBox(3) = PdfTypeNumber.Create(cropBox(3).As(Of PdfTypeNumber).FloatValue + 72)
        mediaBox(3) = PdfTypeNumber.Create(mediaBox(3).As(Of PdfTypeNumber).FloatValue + 72)

        pageDict("CropBox") = cropBox
        pageDict("MediaBox") = mediaBox

        ToolStripLabel1.Text = cropBox(0).As(Of PdfTypeNumber).FloatValue & "," &
                               cropBox(1).As(Of PdfTypeNumber).FloatValue & "," &
                               cropBox(2).As(Of PdfTypeNumber).FloatValue & "," &
                               cropBox(3).As(Of PdfTypeNumber).FloatValue & "   " &
                               PdfViewer1.CurrentPage.Height

        PdfViewer1.Refresh()
    End Sub

Edited by moderator Sunday, February 24, 2019 8:40:07 AM(UTC)  | Reason: Not specified

Paul Rayman  
#4 Posted : Sunday, February 24, 2019 8:56:45 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 724

Thanks: 1 times
Was thanked: 87 time(s) in 86 post(s)
This code works fine for me

Code:
var pageDict = pdfViewer1.CurrentPage.Dictionary;
var mediaBox = pageDict["MediaBox"].As<PdfTypeArray>();
mediaBox[3] = PdfTypeNumber.Create(mediaBox[3].As<PdfTypeNumber>().FloatValue + 72);
pdfViewer1.CurrentPage.Dispose();
pdfViewer1.UpdateLayout();


I guess you should call both page.Dispose() to force the page to reload and pdfViewer1.UpdateLayout() to force PdfViewer to redraw itself;

Edited by user Sunday, February 24, 2019 9:05:18 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Paul Rayman for this useful post.
oberon232 on 2/24/2019(UTC)
oberon232  
#5 Posted : Sunday, February 24, 2019 2:54:33 PM(UTC)
oberon232

Rank: Newbie

Groups: Registered
Joined: 2/23/2019(UTC)
Posts: 6
United States
Location: FL

Thanks: 1 times
Paul Rayman, you absolutely rock!
Thanks a ton.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.