Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Web Edition/WebPicture from PDF Page Web1
Function:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/Web Edition/WebPicture from PDF Page Web1
This example is the version from Tue, 9th Mar 2020.
Project "WebPicture from PDF Page Web1.xojo_binary_project"
Class App Inherits WebApplication
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
End Class
Class MainPage Inherits WebPage
Control ImageView1 Inherits WebImageView
ControlInstance ImageView1 Inherits WebImageView
End Control
Control Timer1 Inherits WebTimer
ControlInstance Timer1 Inherits WebTimer
EventHandler Sub Action() start End EventHandler
End Control
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Function RenderPDFWebPicture(file as FolderItem, pageIndex as integer, width as integer, height as integer) As WebPicture Dim pdf As New DynaPDFMBS // create PDF environment and setup If pdf.CreateNewPDF(Nil) Then if pdf.SetImportFlags(pdf.kifImportAsPage + pdf.kifImportAll) then // open source file If pdf.OpenImportFile(file) >= 0 Then // import file if pdf.Append then If pdf.ImportPageEx(PageIndex, 1.0, 1.0) >= 0 Then if pdf.EndPage then // make a jpeg If pdf.SetJPEGQuality(80) Then // render 1x If pdf.RenderPageToImage(pageIndex, Nil, 72, width, height, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) Then Dim LowData As String = pdf.GetImageBuffer // render 2x If pdf.RenderPageToImage(pageIndex, Nil, 144, width, height, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) Then Dim HighData As String = pdf.GetImageBuffer // now build 1x picture Dim w As New WebPicture(LowData, "page.jpg") // and put in 2x data w.data = HighData // and return with HiDPI content Return w end if end if end if end if end if end if end if end if End If End Function
Function RenderPDFWebPicture(PDFData as String, pageIndex as integer, width as integer, height as integer) As WebPicture Dim pdf As New DynaPDFMBS // create PDF environment and setup If pdf.CreateNewPDF(Nil) Then if pdf.SetImportFlags(pdf.kifImportAsPage + pdf.kifImportAll) then // open source file If pdf.OpenImportBuffer(PDFData) >= 0 Then // import file if pdf.Append then If pdf.ImportPageEx(PageIndex, 1.0, 1.0) >= 0 Then if pdf.EndPage then // make a jpeg If pdf.SetJPEGQuality(80) Then // render 1x If pdf.RenderPageToImage(pageIndex, Nil, 72, width, height, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) Then Dim LowData As String = pdf.GetImageBuffer // render 2x If pdf.RenderPageToImage(pageIndex, Nil, 144, width, height, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) Then Dim HighData As String = pdf.GetImageBuffer // now build 1x picture Dim w As New WebPicture(LowData, "page.jpg") // and put in 2x data w.data = HighData // and return with HiDPI content Return w end if end if end if end if end if end if end if end if End If End Function
Sub Start() // quickly render one PDF with given page dim w as integer = ImageView1.Width dim h as integer = ImageView1.Height dim file as Folderitem = FindFile("license.pdf") if file = nil or file.Exists = false then MsgBox "Please change path to test file." else dim wp as WebPicture = RenderPDFWebPicture(file, 1, w, h) ImageView1.Picture = wp end if End Sub
End Class
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 Return 0 // ignore 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.

Feedback: Report problem or ask question.

The biggest plugin in space...