Example: /DynaPDF/Extract image objects

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Extract image objects


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/Extract image objects

This example is the version from Fri, 7th Jan 2021.

Project "Extract image objects.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim f as FolderItem = GetOpenFolderItem(MyFileTypes.Pdf) if f=nil then quit end if dim p as new MyDynapdfMBS p.SetLicenseKey "Lite" // For this example you can use a Lite, Pro or Enterprise License call p.CreateNewPDF(nil) // Skip anything that is not required call p.SetImportFlags p.kifImportAll + p.kifImportAsPage // From which PDF file do you want to extract the images? call p.OpenImportFile(f, p.kptOpen, "") // Comment this out if you want to extract the images from specific pages only call p.ImportPDFFile(1, 1.0, 1.0) // Uncomment this section if you want to extract images from specific pages only 'dim pageCount as integer = p.GetInPageCount 'for i as integer = 1 to pageCount ' call p.ImportPDFPage(i) 'next call p.CloseImportFile dim dest as FolderItem = SpecialFolder.Desktop dim b as BinaryStream dim counter as integer = 0 dim n as integer = p.GetImageObjCount-1 for i as integer = 0 to n dim Image as DynaPDFImageMBS = p.GetImageObj(i, p.kpfNone) counter=counter+1 Select case Image.filter case DynapdfMBS.kdfDCTDecode // JPEG f=dest.Child(str(Counter)+".jpg") b=f.CreateBinaryFile("") if b<>Nil then b.Write image.Buffer b.Close end if case DynapdfMBS.kdfJPXDecode // JPEG 2000 f=dest.Child(str(Counter)+".jp2") b=f.CreateBinaryFile("") if b<>Nil then b.Write image.Buffer b.Close end if else // anything else f=dest.Child(str(Counter)+".tif") if p.CreateImage(f, p.kifmTIFF) then call p.addimage(p.kcfLZW, p.kicNone, image) call p.CloseImage end if end Select next End EventHandler
End Class
Class Window1 Inherits Window
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
MyFileTypes
Filetype application/pdf
End MyFileTypes
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.


💬 Ask a question or report a problem