Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Not setting page sizes in a loop
  FAQ FAQ  Forum Search   Register Register  Login Login

Not setting page sizes in a loop

 Post Reply Post Reply
Author
Message
dptulk View Drop Down
Beginner
Beginner
Avatar

Joined: 24 Feb 12
Location: Ohio
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote dptulk Quote  Post ReplyReply Direct Link To This Post Topic: Not setting page sizes in a loop
    Posted: 24 Feb 12 at 10:38PM
Still working on my imposing app.  Got all the good stuff done and threw it in a loop for multiple pages and not it wont keep the pagesize that I specify.  The output ends up being the same as the original...  This is baffling me.   Anyone have any thoughts?

Code:

  For i = 1 To numpages

            ThisCaptureID = QP.CapturePage(i)

            'SET A NEW PAGE TO PLACE THE CAPTURED PAGE ON
            ThisPageNum = QP.NewPage()

            QP.SetOrigin(1)
            QP.SetPageDimensions(NewPageWidth, NewPageHeight)

            'DRAW CAPTURED PAGE INTO NEW LAYOUT / AS 2 x 2 ARRAY 

            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, 0 + LeftMargin, pagewidth, pageheight)


            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, 0 + LeftMargin, pagewidth, pageheight)


            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, pageheight + LeftMargin, pagewidth, pageheight)


            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, pageheight + LeftMargin, pagewidth, pageheight)



            If AddCrops.Checked = True Then
                'DRAW CROP MARKS ######################
                Dim crResponse
                Dim StartX, StartY, EndX, EndY

               
                'END CROP MARKS 

                lblStatusTxt.Text = "Page " & i & " of " & numpages & " imposed..."
            End If

        Next

        Dim DestFile = Path.GetFileNameWithoutExtension(SrcFileName) & "_IMPOSED.PDF"
        Dim DestDirectory = Path.GetDirectoryName(srcFilePath)

        QP.SaveToFile(DestDirectory & "\" & DestFile)

        QP = Nothing
Back to Top
jpbro View Drop Down
Senior Member
Senior Member


Joined: 29 Mar 11
Status: Offline
Points: 77
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 24 Feb 12 at 11:06PM
The return values of QP.PageWidth and QP.PageHeight don't match what you've passed to QP.SetPageDimensions as NewPageWidth and NewPageHeight?

What is your return value of QP.SetPageDimensions? It should be 1 if successful. If not, what is the value of QP.LastErrorCode after you call SetPageDimensions?

Also, can you attach your output PDF?
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 25 Feb 12 at 11:15AM
Hi,

so it works as you want:

procedure TForm1.Button1Click(Sender: TObject);
var
  i, n,
  cid,
  PageNum: integer;
  pw, ph,
  npw, nph: double;
begin
  QP := TQuickPDF.Create;
  if QP.UnlockKey({$I PDFkey.inc})=1 then;
  QP.LoadFromFile(fn ,'');  // fn has a valid name of PDF-file
  n := QP.PageCount;
  pw := QP.PageWidth;
  ph := QP.PageHeight;
  npw := pw*2;     // to get enough place
  nph := ph*2;
  for i:=1 to n
  do begin
    PageNum := QP.NewPage;    // ever the last = n+1
    cid := QP.CapturePage(1); // ever the first! capture deletes!
// now we have again n pages, value of PageNum becomes wrong.
// But we knew the newpage we want to draw on is selected and on location n
    QP.SetOrigin(1);
    QP.SetPageDimensions(npw, nph);
// DRAW CAPTURED PAGE INTO NEW LAYOUT / AS 2 x 2 ARRAY
    QP.DrawCapturedPage(cid, 0, 0, pw, ph);
    QP.DrawCapturedPage(cid, pw, 0, pw, ph);
    QP.DrawCapturedPage(cid, 0, ph, pw, ph);
    QP.DrawCapturedPage(cid, pw, ph, pw, ph);
  end;
  QP.SaveToFile(ChangeFileExt(fn, '_imposed.pdf'));
  QP. Free;
end;

In your code is a very small but powerfull mistake:

CapturePage(i)

This small thing makes a lot of trouble, because on step i=2 you take for capture page with old number 3 and so on...

If your input has two or more page, after your loop old page 2 becomes page 1 without changes.

Why?
After capturing (even used or not) the choosen page is deleted, so all pagenumbers after it change. So you have to take ever the first page. On the other hand NewPage appends, so you have after this n pages, as on start. Ever the actually first page goes and comes back imposed on last (new) page.


Cheers,
Werner



Edited by edvoigt - 28 Feb 12 at 4:38PM
Back to Top
dptulk View Drop Down
Beginner
Beginner
Avatar

Joined: 24 Feb 12
Location: Ohio
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote dptulk Quote  Post ReplyReply Direct Link To This Post Posted: 28 Feb 12 at 2:54AM
I'm following you here.  I see where that could be.  How do I move to a particular page then?  in my next trial, I do the following:

       For i = 1 To numpages

            'SET A NEW PAGE TO PLACE THE CAPTURED PAGE ON SO THAT I HAVE MY PAGE READY
            ThisPageNum = QP.NewPage()
            QP.SetOrigin(1)
            QP.SetPageDimensions(NewPageWidth, NewPageHeight)

            'CAPTURE THE CURRENT PAGE (DELETES IT FROM THE DOCUMENT)
            ThisCaptureID = QP.CapturePage(i)

            'DRAW CAPTURED PAGE INTO NEW LAYOUT / AS 2 x 2 ARRAY (THIS FAILS AND DRAWS IT ONTO THE PAGE FOLLOWING THE CAPTURE)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, 0 + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, 0 + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, pageheight + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, pageheight + TopMargin, pagewidth, pageheight)


        Next
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 28 Feb 12 at 9:27AM
Hi,

you didn't understand me. You have in your loop only to exchange in line

ThisCaptureID = QP.CapturePage(i)

index i by constant 1. Because of captering ever the first page, you get every (old) page of document in their right order one after the other. Newpage ever appends and so on the end of document grows step by step the new doc as you want it.

Let's assume, the doc has 3 Pages:

At start it looks after Newpage so:
1, 2, 3, n1 (n1 denotes the coming new page 1).

After captering page on place 1 is no more there and we have 3 pages in document:
2, 3, n1

From Newpage n1 is selected and you may draw the captured (old) page 1 so often as you want anywhere on n1. The next loop-step shall take page 2. It is now on first place, therefore we dont't capture page i (it would be the page on place 2, it is page 3). We take ever the page on first place!

After this wie have
3, n1, n2

and in last loop
3, n1, n2, n3
n1, n2, n3.

To your question:
How do I move to a particular page then?

You have to distinguish between the pagenumber as in QPL is used. It denotes ever the ordering number (or number of location) in a document, not what is written as pagenumber anywhere on page.

You may select a page over her pagenumber in this sense, to manipulate it and with QP.MovePage you may move selected page from one location to another. But in your lop is no moving needed.


In hope, that my answer is what you want,

Werner
Back to Top
dptulk View Drop Down
Beginner
Beginner
Avatar

Joined: 24 Feb 12
Location: Ohio
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote dptulk Quote  Post ReplyReply Direct Link To This Post Posted: 28 Feb 12 at 3:42PM
Thanks a bunch Ed.  This is where I ended up and it works brilliantly.

       'LOAD THE FILE AND CAPTURE WIDTH AND HEIGHT
        QP.LoadFromFile(SrcFileName, "")

        Dim numpages As Integer = QP.PageCount
        Dim pagewidth = QP.PageWidth()
        Dim pageheight = QP.PageHeight()
        Dim NewPageWidth = ReturnPaperWidth()
        Dim NewPageHeight = ReturnPaperHeight()
        Dim LeftMargin As Integer = (NewPageWidth - (pagewidth * 2)) / 2
        Dim TopMargin As Integer = (NewPageHeight - (pageheight * 2)) / 2
        Dim ThisCaptureID, ThisPageNum, drResponse

        For i = 1 To numpages

            If numpages = 1 Then

                'CREATE THE NEW PAGE FIRST
                ThisPageNum = QP.NewPage()

                'SET THE ORIGIN TO UPPER RIGHT
                QP.SetOrigin(1)

                'SET THE PAGE DIMENSIONS OF THE NEW PAGE
                QP.SetPageDimensions(NewPageWidth, NewPageHeight)

                'CAPTURE THE CURRENT PAGE (DELETES IT FROM THE DOCUMENT)
                ThisCaptureID = QP.CapturePage(1)
            Else
                'CAPTURE THE CURRENT PAGE (DELETES IT FROM THE DOCUMENT)
                ThisCaptureID = QP.CapturePage(1)

                'CREATE THE PAGE TO PLACE THE CAPTURE ON
                ThisPageNum = QP.NewPage()

                'SET THE ORIGIN TO UPPER RIGHT
                QP.SetOrigin(1)

                'SET THE PAGE DIMENSIONS OF THE NEW PAGE
                QP.SetPageDimensions(NewPageWidth, NewPageHeight)

            End If

            'DRAW CAPTURED PAGE INTO NEW LAYOUT / AS 2 x 2 ARRAY 
            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, 0 + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, 0 + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, 0 + LeftMargin, pageheight + TopMargin, pagewidth, pageheight)
            drResponse = QP.DrawCapturedPage(ThisCaptureID, pagewidth + LeftMargin, pageheight + TopMargin, pagewidth, pageheight)

            If AddCrops.Checked = True Then
                'DRAW CROP MARKS 


            End If

        Next

        Dim DestFile = Path.GetFileNameWithoutExtension(SrcFileName) & "_IMPOSED.PDF"
        Dim DestDirectory = Path.GetDirectoryName(srcFilePath)

        QP.SaveToFile(DestDirectory & "\" & DestFile)

        QP = Nothing
Back to Top
edvoigt View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 Mar 11
Location: Berlin, Germany
Status: Offline
Points: 111
Post Options Post Options   Thanks (0) Thanks(0)   Quote edvoigt Quote  Post ReplyReply Direct Link To This Post Posted: 28 Feb 12 at 4:13PM
Hi,

I see, you're on the right way.

Only a small advice. It is a good idea, to do the newpage ever as first statement in loop. Every PDF has at least one page, so this new page is ever used for drawing the captured first page. There is no risk. Your test

if pagenum=1 ...

is not needed.

Start in the loop ever with this both statements and it works fine, as you'll see

      For i = 1 To numpages
        'CREATE THE NEW PAGE FIRST this is where TO PLACE THE CAPTURE ON                       ThisPageNum = QP.NewPage()
' now Newpage is selected and all operations go there
' capturing dont change the selection, it does not disturb anything
' NewPage before makes sure, that your document cannot get empty (forbidden by QPL!)
        ThisCaptureID = QP.CapturePage(1)
        'SET THE ORIGIN TO UPPER RIGHT
        QP.SetOrigin(1)
        'SET THE PAGE DIMENSIONS OF THE NEW PAGE
        QP.SetPageDimensions(NewPageWidth, NewPageHeight)
        'CAPTURE THE CURRENT PAGE (DELETES IT FROM THE DOCUMENT)
        'DRAW CAPTURED PAGE INTO NEW LAYOUT / AS 2 x 2 ARRAY

... and so on with your imposition stuff.

Happy coding,

Werner
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store