Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Web Edition/WebPicture from PDF Page
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
This example is the version from Thu, 6th Apr 2016.
Project "WebPicture from PDF Page.rbp"
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 WebPage1 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 MyDynaPDFMBS // 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, "")>=0 then // impor tfile 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 if pdf.RenderPageToImage(pageIndex, nil, 72, width, height, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfJPEG, pdf.kifmJPEG) then dim data as string = pdf.GetImageBuffer dim w as new WebPicture(data, "page.jpg") // and return Return w 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:

Feedback, Comments & Corrections

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

MBS Xojo PDF Plugins