Changing pdf page dimensions

700 Views Asked by At

I've got a program that stamps a page number on each file of a pdf. The problem I'm having is sometimes if there is text already where the stamp should go, it writes over it making both illegible. We don't want to write over or delete any text that might be there, so I'm trying to change the size of the pages so that a small amount of white space is appended to each page for each stamp to go in.

doc.Read(fi.FullName)

            For i = 1 To doc.PageCount

                doc.PageNumber = i

                doc.SetInfo(doc.Page, "/MediaBox:Rect", doc.MediaBox.Left.ToString + " " + (doc.MediaBox.Top + 40).ToString + " " + (doc.MediaBox.Right + 0).ToString + " " + (doc.MediaBox.Bottom - 0).ToString)

                pgwidth = 0
                pgwidth = Convert.ToString(doc.CropBox.Width - 11)
                pgheight = Convert.ToString(doc.MediaBox.Height + 40)
                doc.Rect.String = doc.MediaBox.Left.ToString + " " + (doc.MediaBox.Top + 40).ToString + " " + (doc.MediaBox.Right + 0).ToString + " " + (doc.MediaBox.Bottom - 0).ToString
                'doc.SetInfo(doc.Page, "/MediaBox:Rect", doc.MediaBox.Left.ToString + " " + (doc.MediaBox.Top + 40).ToString + " " + (doc.MediaBox.Right + 0).ToString + " " + (doc.MediaBox.Bottom - 40).ToString)

                doc.Rect.String = "11 20 " + pgwidth + " 10"
                doc.Color.String = "0 0 0"
                'doc.FillRect()

                'doc.Rect.String = "11 20 580 10"

                doc.FontSize = 10
                doc.HPos = 0
                doc.AddText("CONFIDENTIAL")

                bates = Bates1.Text + "_" + x.ToString("D" + batesLen.ToString)

                doc.FontSize = 10
                doc.HPos = 1.0
                doc.AddText(bates)

                x = x + 1

            Next

I've succeeded in altering the size of the pages, but the blank space always appears at the top of the page. I need this space at the bottom of the page, and all attempts at moving or translating the contents of the page haven't worked out.

How can I essentially extend the bottom of the page of a pdf? Or, is there any other way to place a page stamp at the bottom of the page without writing over text that could be already there?

1

There are 1 best solutions below

0
On

Maybe you can replace that page by a shrunken version of it. This will give you the margins you nedd, keeping a "printable size".

Copy all the pages on a New AbCpDF Doc, and perform a small reduction of that sheets, doing something like this:

Dim shrink_x, shrink_x As Integer ' play with them
Dim oRecOriginal, oRecFinal As WebSupergoo.ABCpdf7.XRect
oRecOriginal = oDocOriginal.Rect
oRecFinal = oDocFinal.Rect

oDocFinal.Rect.Inset(shrink_x, shrink_x) ' reduce sheet
oDocFinal.AddImageDoc(oDocOriginal, 1, oRecOriginal) ' add reduced sheet