Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Show Differences


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/Show Differences

This example is the version from Thu, 6th Apr 2016.

Project "Show Differences.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() // register plugin here End EventHandler
End Class
Class MainWindow Inherits Window
Control CanvasPDF1 Inherits Canvas
ControlInstance CanvasPDF1 Inherits Canvas
End Control
Control CanvasPDF2 Inherits Canvas
ControlInstance CanvasPDF2 Inherits Canvas
End Control
Control CanvasDiff3 Inherits Canvas
ControlInstance CanvasDiff3 Inherits Canvas
End Control
Control LoadButton1 Inherits PushButton
ControlInstance LoadButton1 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) LoadPDF1 f End EventHandler
End Control
Control LoadButton2 Inherits PushButton
ControlInstance LoadButton2 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) LoadPDF2 f End EventHandler
End Control
Control NextButton Inherits PushButton
ControlInstance NextButton Inherits PushButton
EventHandler Sub Action() PageIndex1 = PageIndex1 + 1 PageIndex2 = PageIndex2 + 1 RenderPDF1 RenderPDF2 showDifferences End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Open() // init once pdf = new MyDynaPDFMBS call pdf.SetImportFlags(pdf.kifImportAll + pdf.kifImportAsPage) call pdf.SetJPEGQuality(90) // for debugging load something right away 'LoadPDF1 FindFile("test1.pdf") 'LoadPDF2 FindFile("test2.pdf") End EventHandler
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
Protected Sub LoadPDF1(f as FolderItem) if f <> nil and f.Exists then PDFFile1 = f PageIndex1 = 1 PageCount1 = 1 // not yet known RenderPDF1 if PDFFile2 <> nil then NextButton.Enabled = PageIndex2 < PageCount2 and PageIndex1 < PageCount1 showDifferences end if end if End Sub
Protected Sub LoadPDF2(f as FolderItem) if f <> nil then PDFFile2 = f PageIndex2 = 1 PageCount2 = 1 // not yet known RenderPDF2 if PDFFile1 <> nil then NextButton.Enabled = PageIndex2 < PageCount2 and PageIndex1 < PageCount1 showDifferences end if end if End Sub
Protected Sub RenderPDF1() canvasPDF1.backdrop = nil dim r as integer // clear everything call pdf.CreateNewPDF(nil) // open PDF r = pdf.OpenImportFile(PDFFile1) if r >= 0 then // ok PageCount1 = pdf.GetInPageCount // get only the one page we need call pdf.Append r = pdf.ImportPageEx(PageIndex1) call pdf.EndPage if r >= 0 then // ok // render it dim p as Picture = pdf.RenderPagePicture(1, CanvasPDF1.Width, CanvasPDF1.Height) CanvasPDF1.backdrop = p end if end if // cleanup call pdf.CloseImportFile call pdf.CloseFile call pdf.FreePDF End Sub
Protected Sub RenderPDF2() canvasPDF2.backdrop = nil dim r as integer // clear everything call pdf.CreateNewPDF(nil) // open PDF r = pdf.OpenImportFile(PDFFile2) if r >= 0 then // ok PageCount2 = pdf.GetInPageCount // get only the one page we need call pdf.Append r = pdf.ImportPageEx(PageIndex2) call pdf.EndPage if r >= 0 then // ok // render it dim p as Picture = pdf.RenderPagePicture(1, CanvasPDF2.Width, CanvasPDF2.Height) CanvasPDF2.backdrop = p end if end if // cleanup call pdf.CloseImportFile call pdf.CloseFile call pdf.FreePDF End Sub
Protected Sub showDifferences() CanvasDiff3.backdrop = nil dim r as integer // clear everything 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 PDF r = pdf.OpenImportFile(PDFFile1) if r >= 0 then // ok // get only the one page we need call pdf.Append r = pdf.ImportPageEx(PageIndex1) call pdf.EndPage if r >= 0 then // ok // open PDF r = pdf.OpenImportFile(PDFFile2) if r >= 0 then // ok PageCount2 = pdf.GetInPageCount // get only the one page we need call pdf.Append r = pdf.ImportPageEx(PageIndex2) call pdf.EndPage if r >= 0 then // ok if pdf.ShowDifferences(1, pdf, 2, true) >= 0 then // render it dim p as Picture = pdf.RenderPagePicture(1, CanvasDiff3.Width, CanvasDiff3.Height) CanvasDiff3.backdrop = p end if end if end if end if end if // cleanup call pdf.CloseImportFile call pdf.CloseFile call pdf.FreePDF End Sub
Property Protected PDF As MyDynaPDFMBS
Property Protected PDFFIle2 As FolderItem
Property Protected PDFFile1 As FolderItem
Property Protected PageCount1 As Integer
Property Protected PageCount2 As Integer
Property Protected PageIndex1 As Integer
Property Protected PageIndex2 As Integer
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
FileTypes1
Filetype application/pdf
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
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer PageBreak = true Return -1 // stop End EventHandler
Property IgnoreWarnings As Boolean
Property PageBreak 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...