Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Raster/DynaPDF Display PDF in memory

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 in memory

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

Project "DynaPDF Display PDF in memory.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 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 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 init(file as FolderItem) // read PDF file in memory dim b as BinaryStream = file.OpenAsBinaryFile(false) dim PDFData as string = b.Read(b.Length) // now go on page = 1 pdf = new MyDynaPDFMBS call pdf.CreateNewPDF(nil) // create pdf in memory call pdf.OpenImportBuffer(PDFData, 0, "") // load from memory call pdf.SetImportFlags(pdf.kifImportAsPage) // important! Import as page 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
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.

The biggest plugin in space...