Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/PDF Diff
Function:
Required plugins for this example: MBS DynaPDF Plugin, MBS MacCG Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Raster/PDF Diff
This example is the version from Sun, 21th Oct 2017.
Project "PDF Diff.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument() dim file as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) if file<>nil then OpenDocument file end if End EventHandler
EventHandler Sub OpenDocument(item As FolderItem) // requires MBS MacCG plugin #if TargetMacOS then dim pdf as CGPDFDocumentMBS = item.OpenAsCGPDFDocumentMBS if pdf<>Nil then dim w as new PDFWindow w.pdf = pdf w.file = item w.init w.show else MsgBox "Not a PDF file?"+EndOfLine+EndOfLine+item.AbsolutePath end if #endif End EventHandler
End Class
Class PDFWindow Inherits Window
Control LeftCanvas Inherits Canvas
ControlInstance LeftCanvas Inherits Canvas
End Control
Control MiddleCanvas Inherits Canvas
ControlInstance MiddleCanvas Inherits Canvas
End Control
Control RightCanvas Inherits Canvas
ControlInstance RightCanvas Inherits Canvas
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control StaticText3 Inherits Label
ControlInstance StaticText3 Inherits Label
End Control
EventHandler Function KeyDown(Key As String) As Boolean // Use cursor up and down to move over pages if asc(key)=31 then if PageIndex<PageCount then PageIndex = PageIndex + 1 render Return true end if end if if asc(key)=30 then if PageIndex>1 then PageIndex = PageIndex - 1 render Return true end if end if End EventHandler
Sub init() PageIndex = 1 PageCount = pdf.PageCount dpdf = new MyDynaPDFMBS call dpdf.CreateNewPDF(nil) call dpdf.OpenImportFile(file, 0, "") call dpdf.ImportPDFFile(1,1.0,1.0) render End Sub
Sub render() dim w,h as integer dim r as CGRectMBS = pdf.MediaBox(PageIndex) w = r.Width h = r.Height dim pic as new Picture(w,h,32) if r<>Nil then pic.Graphics.DrawCGPDFDocumentMBS(pdf, r, PageIndex) end if LeftCanvas.Backdrop = pic dim dpic as Picture = dpdf.RenderPagePicture(pageindex, w, h, dpdf.kpsFitBest) RightCanvas.Backdrop = dpic MiddleCanvas.Backdrop = DiffPicturesMBS(pic, dpic, false) End Sub
Property PageCount As Integer
Property PageIndex As Integer
Property dpdf As MyDynaPDFMBS
Property file As FolderItem
Property pdf As CGPDFDocumentMBS
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
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
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 FileMaker Plugins