Example: /DynaPDF/Raster/DynaPDF Display PDF

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/DynaPDF Display PDF


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/DynaPDF Display PDF

This example is the version from Thu, 27th Mar 2019.

Project "DynaPDF Display PDF.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument() dim file as FolderItem file = GetOpenFolderItem(FileTypes1.Pdf) if file<>nil then OpenDocument file end if End EventHandler
EventHandler Sub OpenDocument(item As FolderItem) dim p as new PDFWindow p.Title = item.DisplayName p.init item p.show End EventHandler
End Class
Class PDFWindow Inherits Window
EventHandler Function KeyDown(Key As String) As Boolean // Next page with space if asc(key)=32 then page = page +1 render redraw Return true end if // render all pages with enter if asc(key)=13 then RenderAllPages Return true end if End EventHandler
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean render redraw Return true End EventHandler
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic<>Nil Then g.DrawPicture pic,0,0 end if End EventHandler
EventHandler Sub Resized() render redraw End EventHandler
EventHandler Sub Resizing() render redraw End EventHandler
Sub RenderAllPages() dim time as integer = ticks // number of pages in this PDF dim c as integer = pdf.GetPageCount // create rasterizer dim r as new DynaPDFRasterizerMBS(pdf, Width, Height) // create options object dim o as new DynaPDFRasterImageMBS o.InitWhite = true o.DefScale = o.kpsFitBest // now raster all pages for page as integer = 1 to c // get a page dim p as DynaPDFPageMBS = pdf.GetPage(page) // and render it if not r.RenderPage(p, o) then MsgBox "Failed to render page "+str(page) Return end if next MsgBox format((Ticks-time)/60.0,"0.0")+" seconds for "+str(c)+" pages." // show last page Self.Invalidate End Sub
Sub init(file as FolderItem) page = 1 pdf = new MyDynaPDFMBS call pdf.CreateNewPDF(nil) call pdf.OpenImportFile(file, 0, "") call pdf.SetImportFlags(pdf.kifImportAsPage) // important! It makes the rendering faster. call pdf.ImportPDFFile(1,1.0,1.0) render Maximize End Sub
Sub redraw() self.Invalidate End Sub
Sub render() pic = pdf.RenderPagePicture(page, Width, Height, pdf.kpsFitBest) End Sub
Property page As Integer
Property pdf As MyDynaPDFMBS
Property pic As Picture
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:

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


💬 Ask a question or report a problem