Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/JBig Test


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/JBig Test

This example is the version from Mon, 2nd Sep 2018.

Project "JBig Test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() MakeTiff dim TiffFile as FolderItem = SpecialFolder.Desktop.Child("license.tif") CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with flate.pdf" ), DynaPDFMBS.kcfFlate CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with JPEG.pdf" ), DynaPDFMBS.kcfJPEG CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with CCITT3.pdf" ), DynaPDFMBS.kcfCCITT3 CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with CCITT4.pdf" ), DynaPDFMBS.kcfCCITT4 CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with LZW.pdf" ), DynaPDFMBS.kcfLZW CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with LZWBW.pdf" ), DynaPDFMBS.kcfLZWBW CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with FlateBW.pdf"), DynaPDFMBS.kcfFlateBW CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with JP2K.pdf" ), DynaPDFMBS.kcfJP2K CreatePDF TiffFile, SpecialFolder.Desktop.Child("pdf with JBIG2.pdf" ), DynaPDFMBS.kcfJBIG2 End EventHandler
Sub CreatePDF(ImageFile as FolderItem, PDFFile as FolderItem, format as integer) dim d as new MyDynapdfMBS dim file as FolderItem d.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License call d.CreateNewPDF PDFFile call d.Append // set a paper size call d.SetPageFormat(d.kpfDIN_A4) call d.SetSaveNewImageFormat(false) // if possible pass through call d.SetUseTransparency(false) // no transparent color call d.SetCompressionFilter(format) // no compression call d.SetResolution(999) // max resolution dim PicWidth, PicHeight, BitsPerPixel as integer dim Zip as Boolean if not d.ReadImageFormat(ImageFile, PicWidth, PicHeight, BitsPerPixel, Zip) then MsgBox "Can't read image size." Return end if dim PageWidth as integer = d.GetPageWidth dim PageHeight as integer = d.GetPageHeight // scale to fit the page size dim f as double = min(PageWidth/PicWidth, PageHeight/PicHeight) dim w as integer = f * PicWidth dim h as integer = f * PicHeight dim x as integer = (PageWidth-w)/2 dim y as integer = (PageHeight-h)/2 // add image to pdf if d.InsertImageEx(x, y, w, h, ImageFile) < 0 then MsgBox "Failed to import image." Return end if call d.EndPage call d.CloseFile End Sub
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Sub MakeTiff() dim PDFFile as FolderItem = FindFile("license.pdf") dim TiffFile as FolderItem = SpecialFolder.Desktop.Child("license.tif") if not TiffFile.Exists then dim pdf as new MyDynapdfMBS // your DynaPDF subclass with Error event filled pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License call pdf.CreateNewPDF nil call pdf.SetImportFlags(pdf.kifImportAll + pdf.kifImportAsPage) // load CharacterMaps if you want to correctly process asian fonts 'call pdf.SetCMapDir(SpecialFolder.Desktop.Child("CMap"), pdf.klcmRecursive) // open file call pdf.OpenImportFile(PDFFile,0,"") // import the first page call pdf.ImportPDFPage(1) // render the page call pdf.RenderPageToImage(1, TiffFile, 600, 0, 0, DynaPDFRasterImageMBS.krfDefault, DynaPDFRasterizerMBS.kpxf1Bit, DynaPDFMBS.kcfFlate, DynaPDFMBS.kifmTIFF) end if End Sub
End Class
Class Window1 Inherits Window
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
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

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


The biggest plugin in space...