Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/Web Edition/Clickable Links in Web Edition/Clickable Links in Web Edition
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/Web Edition/Clickable Links in Web Edition/Clickable Links in Web Edition
This example is the version from Mon, 8th Apr 2012.
Project "Clickable Links in Web Edition.xojo_binary_project"
Class App Inherits WebApplication
End Class
Class Session Inherits WebSession
End Class
Class WebPage1 Inherits WebPage
Control view Inherits MyView
ControlInstance view Inherits MyView
End Control
Control LinkView Inherits MyWebImageView
ControlInstance LinkView(0) Inherits MyWebImageView
End Control
EventHandler Sub Open() // We extract annotations to build imageviews for the links on top of the rendered page // find test file dim file as FolderItem = FindTestFile if file = nil then MsgBox "Failed to find test.pdf" Return end if dim p as new MyDynapdfMBS p.SetLicenseKey "Pro" // For this example you can use Pro or Enterprise License if p.CreateNewPDF(nil) then // Skip anything that is not required if p.SetImportFlags(p.kifImportAll+p.kifImportAsPage) then // From which PDF file do you want to extract the images? if p.OpenImportFile(file, p.kptOpen, "")>=0 then // import pages if p.ImportPDFFile(1, 1.0, 1.0)>0 then if p.CloseImportFile then // render the page dim page as DynaPDFPageMBS = p.GetPage(1) if page<>nil then dim r as DynaPDFRectMBS = page.BBox(page.kpbMediaBox) dim cr as DynaPDFRectMBS = page.BBox(page.kpbCropBox) if cr<>Nil then r= cr dim w as integer = r.Right - r.Left dim h as integer = if p.RenderPageToImage(1, nil, 72, w, h, DynaPDFRasterImageMBS.krfDefault, DynaPDFRasterizerMBS.kpxfRGB, DynaPDFMBS.kcfFlate, DynaPDFMBS.kifmPNG) then dim buf as string = p.GetImageBuffer dim wpic as new WebPicture(buf, "file.png") // WebPicture data constructor is new in RS 2011r4 view.PDFImage.Width = w view.PDFImage.Height = h view.PDFImage.Picture = wpic p.FreeImageBuffer // lookup all links dim u as integer = p.GetAnnotCount-1 for i as integer = 0 to u dim b as DynaPDFAnnotationExMBS = p.GetAnnotEx(i) dim bbox as DynaPDFRectMBS = b.BBox if b.Type = p.katWebLink then dim url as string = b.DestFile System.DebugLog "Link to: "+url dim l as linkview = self.AddLinkView 'l.Picture = RandomPicture l.targetURL = url l.Cursor = System.WebCursors.FingerPointer l.Left = bbox.Left = h - l.Height = - bbox.Bottom l.Width = bbox.Right - bbox.Left end if next end if end if end if end if end if end if end if End EventHandler
Function FindTestFile() As FolderItem dim folder as FolderItem = app.ExecutableFile.Parent dim file as FolderItem = folder.Child("test.pdf") while file = nil or file.Exists = false folder = folder.Parent if folder = nil then Return nil file = folder.Child("test.pdf") wend Return file End Function
End Class
Class MyView Inherits WebContainer
Control PDFImage Inherits WebImageView
ControlInstance PDFImage Inherits WebImageView
End Control
Control Link Inherits WebImageView
ControlInstance Link Inherits WebImageView
EventHandler Sub Open() if DebugBuild then dim p as new Picture(100,100,32) p.Graphics.ForeColor = &cFF0000 p.Graphics.FillRect 0,0,100,100 me.Picture = p end if End EventHandler
End Control
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 // and display dialog: dim msg as string // 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 msg="A warning occurred while processing your PDF code." else msg="An error occurred while processing your PDF code." end if msg = msg + EndOfLine + EndOfLine + str(ErrorCode)+": "+ErrorMessage MsgBox msg IgnoreWarnings = true Return 0 // ignore End EventHandler
Property IgnoreWarnings As Boolean
End Class
Class MyWebImageView Inherits WebImageView
EventHandler Sub MouseDown(X As Integer, Y As Integer, Details As REALbasic.MouseEvent) ShowURL TargetURL End EventHandler
Property TargetURL As string
End Class
End Project

See also:

Feedback, Comments & Corrections

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

The biggest plugin in space...

MBS Xojo blog

Start Chat