PDF Height/Width after Rotation

Discussions about PDF management.
Post Reply
rclendenon
Posts: 18
Joined: Tue Mar 20, 2012 4:36 pm

PDF Height/Width after Rotation

Post by rclendenon » Thu Jun 21, 2012 7:00 pm

Using the 'RotatePage' feature I am able to successfully rotate a pdf. However, the page width and height are the same as for the pre-rotated pdf. For example, a pdf originally has a height of 3032 points and width of 2160 points. I rotate the pdf 90 degrees and save the pdf so that the pdf is displayed with a height of 2160 and a width of 3032. However, when I run the GetPageWidth and GetPageHeight functions they return the values of the original pdf. If I try to add a stamp using the 'DrawRotatedStamp' feature, the pdforigin, dstx, dsty, and angle of rotation are based off of the original pdf and not the rotated. Is there a way to change the origin and dimensions to the rotated pdf?

Thanks,
Russell

rclendenon
Posts: 18
Joined: Tue Mar 20, 2012 4:36 pm

Re: PDF Height/Width after Rotation

Post by rclendenon » Fri Jun 22, 2012 3:55 pm

I have found a work around for this problem. Below is a sample of the code I used (Visual FoxPro):

Code: Select all


cFile = 'c:\test.pdf'

loGDPDF = CREATEOBJECT('gdPicture.gdPicturePDF')
loGdPDF.LoadFromFile(cFile,.T.)

*Rotate page 90 degrees
loGdPDF.RotatePages(90)

loGdPDF.SaveToFile(cFile)
loGdPDF.CloseDocument()

*need to convert pdf to image and import into blank pdf to flatten properties so that pdf rotation shows up as 0
*if this is not done then all the origins and rotation of future processes will not work as expected
loGDPDF1 = CREATEOBJECT('gdPicture.gdPicturePDF')
loGdPDF2 = CREATEOBJECT('gdPicture.gdPicturePDF')
****Create PictureImaging Object****
loGdPicture = CREATEOBJECT('GdPicture.GdPictureImaging')

*create new pdf
loGDPDF2.NewPDF_2(.F.)
*Load rotated pdf
loGDPDF1.LoadfromFile(cFile,.t.)

loGDPDF1.SelectPage(1)
nImageId = loGDPDF1.RenderPageToGdPictureImageEx(200,.T.)  &&Convert pdf to image using 200 dpi
IF nImageId!=0
	loGDPDF2.AddImageFromGdPictureImage(nImageId,.F.,.T.)
	loGdPicture.ReleaseGdPictureImage(nImageId)
ENDIF

loGdPDF2.SaveToFile(cFile)

loGdPDF2.CloseDocument()
loGDPDF1.CloseDocument()



If there is a better way to do this please feel free to enlighten me.

Thanks,
Russell

SamiKharma
Posts: 352
Joined: Tue Sep 27, 2011 11:47 am

Re: PDF Height/Width after Rotation

Post by SamiKharma » Sat Jun 23, 2012 1:27 pm

Hi,

This is due to the pdf spec. A rotated page is rotated, and what is changed is the PDFRotation, and not the height and the width. Basically you have to use GetPageRotation:
https://www.gdpicture.com/guides/gdpicture/v8/html/con ... ation.html
As for the coordinate system:
https://www.gdpicture.com/guides/gdpicture/v8/html/con ... rigin.html

Hope this helps.
Best Regards,
Sami

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest