Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/List Images


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/List Images

This example is the version from Sat, 5th Aug 2016.

Project "List Images.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PDFButton Inherits PushButton
ControlInstance PDFButton Inherits PushButton
EventHandler Sub Action() dim file as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) if file = nil then Return pdf = new MyDynaPDFMBS pdf.SetLicenseKey "Lite" // For this example you can use Lite, Pro or Enterprise License call pdf.CreateNewPDF(nil) // Skip anything that is not required dim flags as integer = BitwiseOr(pdf.kifImportAll, pdf.kifImportAsPage) call pdf.SetImportFlags flags // From which PDF file do you want to extract the images? call pdf.OpenImportFile(file) // import pages call pdf.ImportPDFFile(1) call pdf.CloseImportFile dim u as integer = pdf.GetImageObjCount-1 for i as integer = 0 to u flags = pdf.kpfDecomprAllImages dim img as DynaPDFImageMBS = pdf.GetImageObj(i, flags) List.AddRow str(i), str(img.Width), str(img.Height), str(img.BufferSize) List.RowTag(List.LastIndex) = img next End EventHandler
End Control
Control ExportButton Inherits PushButton
ControlInstance ExportButton Inherits PushButton
EventHandler Sub Action() if List.ListIndex < 0 then Return dim img as DynaPDFImageMBS = List.RowTag(List.ListIndex) if img = nil then Return dim filter as string dim defaultName as string dim imageFormat as integer dim imageFilter as integer Select case img.Filter case DynaPDFMBS.kdfDCTDecode // we can pass through jpeg filter = FileTypes1.Jpeg defaultname = "image.jpg" imageFormat = DynaPDFMBS.kifmJPEG imageFilter = DynaPDFMBS.kcfJPEG else // all other are converted to TIFF here filter = FileTypes1.ImageTiff defaultname = "image.tif" imageFormat = DynaPDFMBS.kifmTIFF imageFilter = DynaPDFMBS.kcfFlate end Select dim f as FolderItem = GetSaveFolderItem(filter, defaultname) if f <> nil then if pdf.CreateImage(f, imageFormat) then if pdf.AddImage(imageFilter, DynaPDFMBS.kicNone, img) then if pdf.CloseImage then f.Launch end if end if end if end if Exception io as IOException MsgBox "Failed to write file." End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub Change() CurrentPicture = nil if me.ListIndex >= 0 then dim img as DynaPDFImageMBS = me.RowTag(me.ListIndex) if img <> nil then #if true then dim jpegData as string = img.PictureData CurrentPicture = Picture.FromData(jpegData) #else // do it in Xojo if img.Filter = DynaPDFMBS.kdfDCTDecode then // JPEG CurrentPicture = picture.FromData(img.Buffer) else // we convert to PNG here to open it if pdf.CreateImage(nil, DynaPDFMBS.kifmPNG) then if pdf.AddImage(DynaPDFMBS.kcfFlate, DynaPDFMBS.kicNone, img) then if pdf.CloseImage then dim buf as MemoryBlock = pdf.GetImageBufferMemory CurrentPicture = picture.FromData(buf) end if end if end if end if #endif end if end if output.Refresh ExportButton.Enabled = CurrentPicture <> nil End EventHandler
End Control
Control Output Inherits Canvas
ControlInstance Output Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) if CurrentPicture <> nil then dim faktor as Double = min( Height / CurrentPicture.Height, Width / CurrentPicture.Width) if faktor > 1.0 then faktor = 1.0 end if // Calculate new size dim w as integer = CurrentPicture.Width * faktor dim h as integer = CurrentPicture.Height * faktor // draw picture in the new size g.DrawPicture CurrentPicture, 0, 0, w, h, 0, 0, CurrentPicture.Width, CurrentPicture.Height end if End EventHandler
End Control
Property CurrentPicture As Picture
Property pdf As MyDynaPDFMBS
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
FileTypes1
Filetype application/pdf
Filetype image/png
Filetype image/jpeg
Filetype image/jpeg2000
Filetype image/tiff
End FileTypes1
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...