Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/PDFKit/PDFKit Print PDF
Function:
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/PDFKit/PDFKit Print PDF
Project "PDFKit Print PDF.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem = GetOpenFolderItem(FileTypes1.Pdf) if f = nil then Return dim p as new PDFDocumentMBS(f) pic = nil if p.pageCount > 0 then dim page as PDFPageMBS = p.pageAtIndex(0) if page <> nil then dim image as NSImageMBS = page.Render if image <> nil then pic = image.CopyPicture end if end if end if self.pdf = p canvas1.Invalidate End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) if pic <> nil then dim faktor as Double = min( g.Height / Pic.Height, g.Width / Pic.Width) // Calculate new size dim w as Integer = Pic.Width * faktor dim h as Integer = Pic.Height * faktor // draw picture in the new size g.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height end if End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim pi as new NSPrintInfoMBS pi.horizontalPagination = pi.NSAutoPagination pi.verticalPagination = pi.NSAutoPagination pi.VerticallyCentered = true pi.HorizontallyCentered = true 'pi.printer = NSPrinterMBS.printerWithName("Your printer") dim n as NSPrintOperationMBS = pdf.PrintOperation(pi, CheckAutoRotate.Value, PopupScaling.ListIndex) n.showsPrintPanel = CheckPrintDialog.Value n.showsProgressPanel = CheckProgressDialog.Value n.jobTitle = "PDF Print" n.runOperationModalForWindow(self) End EventHandler
End Control
Control CheckPrintDialog Inherits CheckBox
ControlInstance CheckPrintDialog Inherits CheckBox
End Control
Control CheckProgressDialog Inherits CheckBox
ControlInstance CheckProgressDialog Inherits CheckBox
End Control
Control CheckAutoRotate Inherits CheckBox
ControlInstance CheckAutoRotate Inherits CheckBox
End Control
Control PopupScaling Inherits PopupMenu
ControlInstance PopupScaling Inherits PopupMenu
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Property pdf As PDFDocumentMBS
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
FileTypes1
Filetype application/pdf
End FileTypes1
End Project

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


💬 Ask a question or report a problem
The biggest plugin in space...