Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CoreGraphics PDF/PDF Viewer White on Black
Function:
Required plugins for this example: MBS MacCG Plugin, MBS Picture Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreGraphics PDF/PDF Viewer White on Black
This example is the version from Sun, 10th Dec 2016.
Project "PDF Viewer White on Black.rbp"
FileTypes
Filetype application/pdf
End FileTypes
Class ViewerWindow Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) drawed=true g.DrawPicture pic,0,0 End EventHandler
End Control
Control FirstButton Inherits BevelButton
ControlInstance FirstButton Inherits BevelButton
EventHandler Sub Action() CurrentPage=1 updatepage End EventHandler
End Control
Control PrevButton Inherits BevelButton
ControlInstance PrevButton Inherits BevelButton
EventHandler Sub Action() CurrentPage=CurrentPage-1 updatepage End EventHandler
End Control
Control NextButton Inherits BevelButton
ControlInstance NextButton Inherits BevelButton
EventHandler Sub Action() CurrentPage=CurrentPage+1 updatepage End EventHandler
End Control
Control LastButton Inherits BevelButton
ControlInstance LastButton Inherits BevelButton
EventHandler Sub Action() CurrentPage=PageCount updatepage End EventHandler
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
EventHandler Sub Change() if me.ListIndex=0 then BackColor=&cFFFFFF else BackColor=&c000000 end if UpdatePage End EventHandler
End Control
Control PopupMenu2 Inherits PopupMenu
ControlInstance PopupMenu2 Inherits PopupMenu
EventHandler Sub Change() UpdatePage End EventHandler
End Control
EventHandler Sub DropObject(obj As DragItem, action As Integer) do if obj.FolderItemAvailable then openfile obj.FolderItem end if loop until not obj.NextItem End EventHandler
Function GetPDFpicture(pdf as cgpdFDocumentMBS) As picture dim r as CGRectMBS dim g as CGContextMBS dim pic as Picture if pdf<>nil then dim f as Double = 1.0 Select case PopupMenu2.ListIndex case 0 f=1.0 case 1 f=1.25 case 2 f=1.5 case 3 f=1.75 case 4 f=2.0 end Select r=pdf.MediaBox(1) r=CGMakeRectMBS(0,0,r.Width*f,r.Height*f) pic = new Picture(r.Width,r.Height,32) pic.Graphics.DrawCGPDFDocumentMBS pdf,r,CurrentPage Select case PopupMenu1.ListIndex case 0 Return pic case 1 Return pic.InvertMBS case 2 return pic.InvertGrayMBS case 3 dim m as Picture = pic.ExtractColorRectangleMaskMBS dim i as Picture = pic.InvertMBS pic.Mask.Graphics.DrawPicture m,0,0 i.Graphics.DrawPicture pic,0,0 Return i end Select end if Exception End Function
Sub UpdateButtons() FirstButton.Enabled=CurrentPage>1 PrevButton.Enabled=CurrentPage>1 NextButton.Enabled=CurrentPage<PageCount LastButton.Enabled=CurrentPage<PageCount End Sub
Sub UpdatePage() drawed=False pic = getpdfpicture(p) Width=pic.Width+40 Height=pic.Height+68 UpdateButtons if not drawed then canvas1.Graphics.DrawPicture pic,0,0 end if End Sub
Sub openfile(f as folderItem) if f<>Nil then p=CGOpenPDFDocumentMBS(F) if p<>nil then Title=f.DisplayName PageCount=p.PageCount CurrentPage=1 UpdatePage else MsgBox "Failed to open PDF file!" end if end if End Sub
Property CurrentPage As Integer
Property PageCount As Integer
Property drawed As Boolean
Property p As CGPDFDocumentMBS
Property Protected pdf As CGPDFDocumentMBS
Property pic As Picture
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub NewDocument() if DebugBuild then dim file as FolderItem = SpecialFolder.Desktop.Child("test.pdf") if file<>Nil and file.Exists then OpenDocument file end if end if End EventHandler
EventHandler Sub OpenDocument(item As FolderItem) dim w as new ViewerWindow w.openfile item End EventHandler
End Class
End Project

See also:

Feedback, Comments & Corrections

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





Links
MBS Xojo PDF Plugins