Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/updatewindow event/Display PDF


Required plugins for this example: MBS Util Plugin, MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Raster/updatewindow event/Display PDF

This example is the version from Mon, 12th Jan 2020.

Project "Display PDF.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() End EventHandler
End Class
Class MainWindow Inherits Window
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() If file = Nil Then // no file? Return end if // new PDF Environment Dim pdf As New MyDynaPDFMBS Call pdf.CreateNewPDF(Nil) // load file Call pdf.OpenImportFile(file, 0, "") Call pdf.SetImportFlags(pdf.kifImportAsPage) // important! It makes the rendering faster. If pdf.GetInPageCount = 0 Then // no pages? Return End If // import the first page only Call pdf.ImportPDFPage(1) dim o as new MyDynaPDFRasterImageMBS o.DefScale = 2 o.NumAnnots = 0 // we force to slow down and show a lot of progress o.UpdateOnPathCount = 10 o.UpdateOnImageCoverage = 0.01 o.Yield = true // give time to other threads // get page Dim page As DynaPDFPageMBS = pdf.GetPage(1) // create rasterizer Dim r As New DynaPDFRasterizerMBS(pdf, 1190, 1684) pic = r.pic // and start rendering If r.RenderPage(page, o) Then // ok, finished pic = r.pic out.InvalidateThreadSafeMBS end if End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() // we start the thread after a second, so you see the drawing better Thread1.run End EventHandler
End Control
Control Out Inherits Canvas
ControlInstance Out Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) #Pragma unused areas // do we have a picture? if pic <> Nil then // draw it g.DrawPicture( pic, 0, 0 ) end if End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() // If Thread1.State <> Thread.NotRunning Then // thread is still running Return End If // file = GetOpenFolderItem( FileTypes1.pdf ) If file = Nil Or file.Exists = False Then // no file selected Return End If // start rendering Thread1.Run End EventHandler
End Control
EventHandler Sub Open() Dim f As FolderItem = SpecialFolder.Desktop.Child("test.pdf") If f = Nil Or f.Exists = False Then MsgBox "Please use ""Create huge Test PDF"" example project to create the PDF file for testing." Else file = f End If End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) g.DrawPicture pic,0,0 End EventHandler
Sub UpdatePic(p as Picture) pic = p // in util plugin Out.InvalidateThreadSafeMBS End Sub
Property file As FolderItem
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
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
Class MyDynaPDFRasterImageMBS Inherits DynaPDFRasterImageMBS
EventHandler Function UpdateWindow(r as DynaPDFRectMBS, pic as variant) As integer dim p as Picture = pic // trigger repaint MainWindow.UpdatePic p Exception // on any exception, cancel Return 1 End EventHandler
End Class
FileTypes1
Filetype application/pdf
End FileTypes1
End Project

See also:

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


The biggest plugin in space...