Print Page | Close Window

PDFs rotate unexpectedly

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2159
Printed Date: 12 Mar 25 at 4:39AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: PDFs rotate unexpectedly
Posted By: chansw
Subject: PDFs rotate unexpectedly
Date Posted: 17 Feb 12 at 4:53PM
I have seen where loading PDFs from files into QPL and then saving them result in the pages being rotated by 90 degrees (CW or CCW).

Is there a best practice way to manage / eliminate this rotation?

Thanks

Jerry

QP.LoadFromFile(origfile, "")
QP.SetOrigin(1)
Dim numpages as Integer = QP.PageCount
For i = 1 to numpages
   QP.SelectPage(1)
   ' QP.NormalizePage(0) ' If uncommmented, I get blank pages
   pagewidth = QP.PageWidth()
   pageheight = QP.PageHeight()
  
   QP.NewPage()
   QP.SetPageDimensions(pagewidth, pageheight)
   capturepageid = QP.CapturePage(1)
   QP.DrawCapturedPage(capturepageid, 36, 36, pagewidth-72, pageheight-72)
Next
QP.SaveToFile("newfile.pdf")





Replies:
Posted By: edvoigt
Date Posted: 17 Feb 12 at 8:47PM
Hi Jerry,

sometimes it happens, that PDFs have inside a rotate-command. The best way is to ask for this.

Look there:
http://www.quickpdf.org/forum/drawcapturedpage-and-autorotation_topic2071_post8882.html?KW=landscape#8882 - http://www.quickpdf.org/forum/drawcapturedpage-and-autorotation_topic2071_post8882.html?KW=landscape#8882

I did give an explanation about background and on the end a short solution. You may manage or eliminate it, as you want.

Cheers,
Werner


Posted By: chansw
Date Posted: 18 Feb 12 at 3:20AM
Thanks Werner for your code sample that show how to use the PageRotation() and RotatePage() functions. For whatever reason however I had to apply the rotation AFTER the new page was drawn; the resulting page did NOT rotate when I placed the RotatePage() command as in your sample code.

Anyways, here's the code that worked for me. I added some subtle hacks (having to do with single vs multiple-page original files). I've added comments to explain when to execute NewPage() based on what I observed through trial-and-error, hopefully I got them right. Being a newb at QPL, I wish the official documentation (reference manuals, etc.) were a bit more comprehensive explaining the subtleties of how things actually work.

Jerry

--

QP.LoadFromFile(origfile, "")
QP.SetOrigin(1)

Dim numpages As Integer = QP.PageCount
For i As Integer = 1 To numpages
   QP.SelectPage(1)
   Dim rotation As Integer = QP.PageRotation()
   pagewidth = QP.PageWidth()
   pageheight = QP.PageHeight()

   If numpages = 1 Then
      QP.NewPage() ' Extra page to allow capturepage() to execute for single page PDFs
   End If
   Dim capturedpageid As Integer = QP.CapturePage(1) ' Deletes page from document
   If numpages > 1 Then
      QP.NewPage() ' Page onto which the captured page will be drawn
   End If
   QP.SetPageDimensions(pagewidth, pageheight)
   QP.DrawCapturedPage(capturedpageid, ...)
   If rotation <> 0 Then
      QP.RotatePage(rotation) ' ***** ROTATE HERE TO MATCH ORIGINAL *****
   End If
Next

QP.SaveToFile(newfile)


Posted By: AndrewC
Date Posted: 22 Feb 12 at 2:58PM
We have just found a bug with NormalizePage(0);  This has been fixed in the 8.14 beta 5 just released yesterday.  It can be download from here.

  http://www.quickpdflibrary.com/blog/2012/02/quick-pdf-library-8-14-beta-5-released/

As a work around is to call QP.SetOrigin(0) before calling QP.NormalizePage(0);

  QP.SetOrigin(0);
  QP.NormalizePage(0);
  QP.SetOrigin(1);

Andrew.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk