Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Create Previews for folder
Function:
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/Create Previews for folder
This example is the version from Tue, 1st Jul 2013.
Project "Create Previews for folder.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() pdf = new MyDynaPDFMBS dim f as FolderItem = SpecialFolder.Desktop.Child("pdfs") if f.Exists = false then MsgBox "please put a folder PDFs on your desktop." Return end if dir f End EventHandler
Sub Dir(folder as FolderItem) dim files() as FolderItem dim c as integer = folder.count for i as integer = 1 to c dim file as FolderItem = folder.TrueItem(i) if file<>nil and file.Visible and Right(file.name,4) = ".pdf" then files.Append file end if next for each file as FolderItem in files process file next End Sub
Sub Process(file as FolderItem) log "Process "+file.Name // start fresh call pdf.CreateNewPDF nil call pdf.SetImportFlags(pdf.kifImportAll + pdf.kifImportAsPage) // import PDF call pdf.OpenImportFile(file) call pdf.Append call pdf.ImportPageEx(1) call pdf.EndPage call pdf.CloseImportFile // render preview dim Resolution as integer = 72 dim Width as integer = 0 // auto dim Height as integer = 0 // auto dim Flags as integer = 0 dim PixFmt as integer = pdf.kpxfRGB dim Filter as integer = pdf.kcfJPEG dim Format as integer = pdf.kifmJPEG if pdf.RenderPageToImage(1, nil, Resolution, Width, Height, Flags, PixFmt, Filter, Format) then dim data as string = pdf.GetImageBuffer dim ImageName as string = Replace(file.name, ".pdf", ".jpg") dim imageFile as FolderItem = file.parent.Child( ImageName ) dim b as BinaryStream = BinaryStream.Create(imageFile, true) b.Write data pdf.FreeImageBuffer end if // explicit shutdown this instance call pdf.CloseFile call pdf.FreeImageBuffer call pdf.FreePDF End Sub
Sub log(s as string) System.DebugLog s LogWindow.List.AddRow s End Sub
Property pdf As DynaPDFMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class LogWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
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:

Feedback, Comments & Corrections

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




Links
MBS Xojo PDF Plugins