Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/updatewindow event/Display PDF 2
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/Raster/updatewindow event/Display PDF 2
This example is the version from Sun, 17th Mar 2012.
Project "Display PDF 2.rbp"
FileType_PDF
Filetype application/pdf
End FileType_PDF
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() // dim pdf As New MyDynaPDFMBS // if file = Nil or file.Exists = False then Return // Call pdf.CreateNewPDF( Nil ) Call pdf.OpenImportFile( file, 0, "" ) Call pdf.SetImportFlags( pdf.kifImportAsPage ) // important! It makes the rendering faster. // import the first page only Call pdf.Append Call pdf.ImportPageEx( 1, 1.0, 1.0 ) Call pdf.EndPage // dim o As New MyDynaPDFRasterImageMBS o.DefScale = 2 o.NumAnnots = 0 o.UpdateOnPathCount = 10 o.UpdateOnImageCoverage = 0.01 o.Yield = True // give time to other threads // dim page As DynaPDFPageMBS = pdf.GetPage( 1 ) // dim r As New DynaPDFRasterizerMBS( pdf, pdf.GetPageWidth, pdf.GetPageHeight ) pic = r.Pic // if r.RenderPage( page, o ) then // ok pic = r.pic Self.Refresh( False ) 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( FileType_PDF.All ) if file = Nil or file.Exists = False then // no file selected Return end if // start rendering Thread1.Run End EventHandler
End Control
Control Out Inherits Canvas
ControlInstance Out Inherits Canvas
EventHandler Sub Paint(g As Graphics) // do we have a picture? if pic <> Nil then // draw it g.DrawPicture( pic, 0, 0 ) end if End EventHandler
End Control
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 // we draw only the changed part dim p as Picture = pic p.Graphics.Pixel(0,0) = p.Graphics.Pixel(0,0) Window1.out.Graphics.DrawPicture( pic, r.Left, r.Top, r.Right, r.Bottom, r.Left, r.Top, r.Right, r.Bottom ) 'Window1.Refresh( False ) 'window1.UpdateNow // Window1.Title = Str( Window1.Title.Val + 1 ) Exception // on any exception, cancel Return( 1 ) End EventHandler
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