Example: /MacCG/CoreGraphics PDF/Create PDF with Picture

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCG/CoreGraphics PDF/Create PDF with Picture


Required plugins for this example: MBS MacCG Plugin, MBS Main Plugin, MBS MacCF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCG/CoreGraphics PDF/Create PDF with Picture

This example is the version from Sun, 17th Mar 2012.

Project "Create PDF with Picture.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
EventHandler Sub Open() dim w,h as integer const size=500.0 dim picFile as folderitem=CreatePicture // source picture file // open picture for dim p as picture=picfile.OpenAsPicture if p=nil then MsgBox "Failed to load picture." end if dim PDFFile as folderitem=SpecialFolder.Desktop.Child("Create PDF with Picture.pdf") dim r as new CGRectMBS // Create the context dim c as CGContextMBS=CGNewPDFDocumentMBS(PDFFile,r,"Picture","","") if c<>nil then w=p.width h=p.height if w>size or h>size then dim factor as Double factor=min(size/p.Height,size/p.Width) w=p.width*factor h=p.Height*factor end if r=new CGRectMBS(0,0,w,h) // We must begin a new page before drawing to a PDF context c.BeginPage(r) dim data as CGDataProviderMBS dim i as CGImageMBS data=CGDataProviderMBS.CreateWithFile(picFile) if data<>nil then // a CGImage based on the JPEG data i=CGCreateImageFromJPEGDataProviderMBS(data,nil,false,0) end if if i=nil then // a CGImage based on the uncompressed image data i=CGCreateImageMBS(p) end if c.DrawPicture(i, r) // We've finished rendering the page c.EndPage c.Flush c=nil // to force the file to be written as we want to launch it pdffile.Launch else MsgBox "Failed to creator file!" end if End EventHandler
Function CreatePicture() As FolderItem dim p as Picture = LogoMBS(500) dim f as FolderItem=SpecialFolder.Desktop.Child("logo.jpg") if f.Exists=false then f.SaveAsJPEG p end if Return f End Function
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
End Project

See also:

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


💬 Ask a question or report a problem