Platforms to show: All Mac Windows Linux Cross-Platform
/DynaPDF/Raster/Batch Convert PDF to JPG
Required plugins for this example: MBS DynaPDF Plugin
Last modified Sun, 17th Mar 2012.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /DynaPDF/Raster/Batch Convert PDF to JPG
Download this example: Batch Convert PDF to JPG.zip
Project "Batch Convert PDF to JPG.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open()
dim folder as FolderItem = SpecialFolder.Desktop.Child("testpdfs")
if folder.Exists = false then
MsgBox "Please change path to your own PDF folder."
end if
dim c as integer = folder.count
for i as integer = 1 to c
dim item as FolderItem = folder.TrueItem(i)
if item<>Nil and right(item.name,4)=".pdf" then
dim pdf as new MyDynaPDFMBS
call pdf.CreateNewPDF(nil)
call pdf.SetImportFlags(pdf.kifImportAsPage)
call pdf.OpenImportFile(item, 0, "")
call pdf.ImportPDFFile(1,1.0,1.0)
dim pc as integer = pdf.GetPageCount
for pi as integer = 1 to pc
System.DebugLog item.name
// query size of imported page
dim rect as DynaPDFRectMBS = pdf.GetInBBox(pi, pdf.kpbCropBox)
if rect = nil then // use media box if there is no crop box
rect = pdf.GetInBBox(pi, pdf.kpbMediaBox)
end if
dim w,h as integer
if rect.Bottom>rect.Top then
h = rect.Bottom - rect.Top
else
h = rect.top - rect.Bottom
end if
if rect.Right>rect.Left then
w = rect.Right - rect.Left
else
w = rect.Left - rect.Right
end if
// render page as picture
dim pic as Picture = pdf.RenderPagePicture(pi, w, h)
dim name as string = ReplaceAll(item.name, ".pdf", "")
dim output as FolderItem = SpecialFolder.Desktop.Child(name+str(pi)+".jpg")
if pic<>Nil then
// older REAL Studio versions
output.SaveAsJPEG pic
// newer REAL Studio versions
'pic.Save(output, pic.SaveAsJPEG)
output.Launch(True)
end if
next
end if
next
quit
End EventHandler
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
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
Download this example: Batch Convert PDF to JPG.zip
The items on this page are in the following plugins: MBS DynaPDF Plugin.
