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/Extract images
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/Extract images
This example is the version from Sun, 17th Mar 2012.
Project "Extract images.rbp"
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 "Pro" // For this example you can use a Pro or Enterprise License call p.CreateNewPDF(nil) // Skip anything that is not required call p.SetImportFlags p.kifContentOnly+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.GetPageCount 'for i as integer = 1 to pageCount 'call p.Append 'call p.ImportPageEx(i, 1.0, 1.0) 'call p.EndPage 'next call p.CloseImportFile dim stack as new MyDynaPDFParseInterfaceMBS stack.dest=SpecialFolder.desktop // destination folder stack.pdf=p 'If you want to create a multipage TIFF then create the output image here 'and call AddImage() only in the callback function. After the loop 'returns call CloseImage() to close the image file. //CreateImage(f, p.kifmTIFF); dim pageCount as integer = p.GetPageCount for i as integer=1 to pageCount call p.EditPage i 'If you want to convert the images into a specific color space then set 'one of the folowing flags (see also TParseFlags in dynapdf.h): ' 'p.kpfDitherImagesToBW // Floyd-Steinberg dithering. 'p.kpfConvImagesToGray 'p.kpfConvImagesToRGB 'p.kpfConvImagesToCMYK ' 'Only one color space conversion flag must be set at time. call p.ParseContent(stack, p.kpfNone) call p.EndPage next // p.CloseImage // Call this function here if you create a multipage TIFF. 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
Class MyDynaPDFParseInterfaceMBS Inherits DynaPDFParseInterfaceMBS
EventHandler Function BeginTemplate(ObjectPtr as integer, Handle as integer, BBox as DynaPDFRectMBS, Matrix as DynapdfMatrixMBS) As integer System.DebugLog "Begin Template" End EventHandler
EventHandler Sub InsertImage(image as DynaPDFImageMBS) dim b as BinaryStream dim f as FolderItem System.DebugLog "Insert Image" 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 pdf.CreateImage(f, pdf.kifmTIFF) then call pdf.addimage(pdf.kcfLZW, pdf.kicNone, image) call pdf.CloseImage end if end Select End EventHandler
Property Counter As Integer
Property dest As folderitem
Property pdf As dynaPDFmbs
End Class
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:

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins