Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/HTMLViewer Mac/Custom Printing with WebPrintMBS
Function:
Required plugins for this example: MBS MacCG Plugin, MBS MacControls Plugin, MBS MacCF Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/Custom Printing with WebPrintMBS
Project "Custom Printing with WebPrintMBS.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
EventHandler Sub Open() me.LoadURL "http://www.monkeybreadsoftware.info/pluginhelp/classes.shtml" //me.LoadURL "http://www.heise.de" End EventHandler
EventHandler Sub TitleChanged(newTitle as String) Title = newTitle End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() MakePDFs End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim i,c as integer dim s as string dim g as Graphics dim p as CGPDFDocumentMBS dim x,y,w,h as integer dim d as CGDataProviderMBS dim r,m as CGRectMBS g=OpenPrinterDialog(page) if g<>nil then w=page.PageWidth-100 h=page.PageHeight-100 x=page.PageLeft+50 y=page.PageTop+50 c=webprint.PrintingStart(w,h) i=0 while i<c s=webprint.PrintingPage(i) d=CGDataProviderMBS.CreateWithData(s) p=CGOpenPDFDocumentMBS(d) if p<>Nil then m=p.MediaBox(1) r=new CGRectMBS(0,0,w,h) if i+1=c then // last page r.Height=(m.Height/m.Width)*r.Width end if r.left=x r.Top=g.height-y-r.Height 'g.DrawRect r.left,y,r.Width,r.Height g.DrawCGPDFDocumentMBS p,r,1 else MsgBox "Failed to open PDF file!" end if i=i+1 if i<c then g.NextPage end if wend webprint.PrintingEnd g=nil MsgBox str(c)+" pages printed." end if End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() if CheckBox1.Value then WebPrint.SheetTarget=self else WebPrint.SheetTarget=nil end if call WebPrint.PageSetup End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action() if CheckBox1.Value then WebPrint.SheetTarget=self else WebPrint.SheetTarget=nil end if call WebPrint.PrintDialog End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() call page.PageSetupDialog End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action() HTMLViewer1.LoadURL EditField1.text End EventHandler
End Control
EventHandler Sub Open() webprint=new MyWebPrintMBS(HTMLViewer1) page=new PrinterSetup End EventHandler
Sub MakePDFs() dim i,c as integer dim f as FolderItem dim s as string dim b as BinaryStream c=webprint.PrintingStart(800,600) i=0 while i<c s=webprint.PrintingPage(i) index=index+1 f=SpecialFolder.Desktop.Child("Page "+str(index)+".pdf") b=f.CreateBinaryFile("") if b<>nil then b.Write s b.Close end if i=i+1 wend webprint.PrintingEnd MsgBox str(c)+" pdf page files created on the desktop." End Sub
Property index As Integer
Property page As printerSetup
Property webprint As webprintMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyWebPrintMBS Inherits WebPrintMBS
EventHandler Sub PageSetupDialogDone(accepted as boolean) MsgBox "Page Setup Dialog done: "+str(accepted) End EventHandler
EventHandler Sub PrintDialogDone(accepted as boolean) MsgBox "Print Dialog done: "+str(accepted) End EventHandler
End Class
End Project

See also:

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

Feedback: Report problem or ask question.

The biggest plugin in space...