Platforms to show: All Mac Windows Linux Cross-Platform
/MacControls/HTMLViewer Mac/Custom Printing
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCG Plugin, MBS MacControls Plugin, MBS MacCF Plugin, MBS Main Plugin, MBS MacCocoa Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/Custom Printing
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCG Plugin, MBS MacControls Plugin, MBS MacCF Plugin, MBS Main Plugin, MBS MacCocoa Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/Custom Printing
Project "Custom Printing.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-40
h=page.PageHeight-40
x=page.PageLeft+20
y=page.PageTop+20
c=HTMLViewer1.PrintingStartMBS(w,h)
i=0
while i<c
s=HTMLViewer1.PrintingPageMBS(i)
d=CGDataProviderMBS.CreateWithData(s)
p=CGOpenPDFDocumentMBS(d)
if p<>Nil then
m=p.MediaBox(1)
r=CGRectMBS.Make(0,0,w,h)
r.Height=(m.Height/m.Width)*r.Width
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
HTMLViewer1.PrintingEndMBS
g=nil
MsgBox str(c)+" pages printed."
end if
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
call HTMLViewer1.PageSetupDialogMBS
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
call HTMLViewer1.PrintDialogMBS
End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action()
call page.PageSetupDialog
End EventHandler
End Control
Control BevelButton1 Inherits BevelButton
ControlInstance BevelButton1 Inherits BevelButton
EventHandler Sub Action()
HTMLViewer1.LoadURL EditField1.text
End EventHandler
End Control
Control EditField1 Inherits TextField
ControlInstance EditField1 Inherits TextField
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action()
HTMLViewer1.mainFrameMBS.frameView.documentView.print
End EventHandler
End Control
EventHandler Sub Open()
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=HTMLViewer1.PrintingStartMBS(800,600)
i=0
while i<c
s=HTMLViewer1.PrintingPageMBS(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
HTMLViewer1.PrintingEndMBS
MsgBox str(c)+" pdf page files created on the desktop."
End Sub
Property index As Integer
Property page As printerSetup
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
End Project
See also:
- /MacControls/HTMLViewer Mac/Google Search
- /MacControls/HTMLViewer Mac/HTMLViewer Extensions
- /MacControls/HTMLViewer Mac/HTMLViewer Image
- /MacControls/HTMLViewer Mac/HTMLViewer Image Tests
- /MacControls/HTMLViewer Mac/HTMLViewer PDF Save and Print
- /MacControls/HTMLViewer Mac/HTMLViewer ScrollHeight
- /MacControls/HTMLViewer Mac/TestWebKit Flash/TestWebKit Flash
- /MacControls/HTMLViewer Mac/WebPolicyDelegate
- /MacControls/HTMLViewer Mac/WebResourceLoadDelegate
- /MacControls/HTMLViewer Mac/WebUIDelegate
The items on this page are in the following plugins: MBS MacControls Plugin.
Feedback: Report problem or ask question.