Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Rotate rotated PDF back


Required plugins for this example: MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Rotate rotated PDF back

This example is the version from Tue, 26th Jun 2017.

Project "Rotate rotated PDF back.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() // if a PDF has a non rotation, we can rotate it to have a by rotating content. dim inputfile as FolderItem = GetOpenFolderItem("") if inputfile = nil then quit Return end if dim pdf as new MyDynapdfMBS dim d as new date pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License dim r as integer = pdf.openimportFile(inputfile) if r < 0 then // error break return end if // create original jpeg call pdf.CreateNewPDF nil call pdf.ImportPDFPage(1) dim fo as FolderItem = SpecialFolder.Desktop.Child("Rotated original.jpg") call pdf.RenderPageToImage(1, fo, 150, 0, 0, 0, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) call pdf.FreePDF // now check orientation call pdf.openimportFile(inputfile) dim orientation as integer = pdf.GetInOrientation(0) // normalize while orientation >= 360 orientation = orientation - 360 wend while orientation < 0 orientation = orientation + 360 wend Select case orientation case 0 MsgBox "nothing to do as this PDF has no orientation" case 90 // rotate 90° content by 270° to correct orientation = 270 case 180 orientation = 180 case 270 orientation = 90 else MsgBox "Invalid orientation: "+str(orientation) quit Return end Select dim f as FolderItem = SpecialFolder.Desktop.Child("Rotated correctly.pdf") call pdf.CreateNewPDF f call pdf.SetImportFlags(pdf.kifImportAll) dim OldTemplate as integer = pdf.ImportPage(1) dim NewTemplate as integer = pdf.RotateTemplate(OldTemplate, orientation) call pdf.CloseImportFile call pdf.Append dim width as integer = pdf.GetTemplWidth(NewTemplate) dim height as integer = pdf.GetTemplHeight(NewTemplate) call pdf.SetPageWidth(width) call pdf.SetPageHeight(height) call pdf.PlaceTemplateEx(NewTemplate, 0, 0, width, height) call pdf.EndPage fo = SpecialFolder.Desktop.Child("Rotated correctly.jpg") call pdf.RenderPageToImage(1, fo, 150, 0, 0, 0, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) call pdf.CloseFile f.Launch // also create a simple one where we just set orientation f = SpecialFolder.Desktop.Child("Rotated not correctly.pdf") call pdf.CreateNewPDF f call pdf.openimportFile(inputfile) call pdf.ImportPDFPage(1) call pdf.EditPage(1) call pdf.SetOrientationEx(0) call pdf.EndPage fo = SpecialFolder.Desktop.Child("Rotated not correctly.jpg") call pdf.RenderPageToImage(1, fo, 150, 0, 0, 0, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) call pdf.CloseFile f.Launch quit End EventHandler
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
Property IgnoreWarnings As Boolean
End Class
End Project

See also:

The items on this page are in the following plugins: MBS DynaPDF Plugin.


The biggest plugin in space...