Using the API to print to pdf
Using the API to print to pdf
(OP)
I'm struggling with printing a MathCAD 13 document using the api in vb.net 2005.
There is a printAll method but it prints to the default printer and you can't go around changing users default printers.
I though maybe I could save to html and then print to pdf but I the html versions don't show headers or footers which is no good.
Anyone tried this?
AAnyone any advice?
There is a printAll method but it prints to the default printer and you can't go around changing users default printers.
I though maybe I could save to html and then print to pdf but I the html versions don't show headers or footers which is no good.
Anyone tried this?
AAnyone any advice?





RE: Using the API to print to pdf
TTFN
RE: Using the API to print to pdf
RE: Using the API to print to pdf
CODE
'Most of this code comes from the VB.net Sample1 project of PdfCreator
'Declare a pdf creator and a pdf error object
Private WithEvents m_PDFCreator As PDFCreator.clsPDFCreator
Private m_PDFError As PDFCreator.clsPDFCreatorError
'Provide a timer object
Private WithEvents m_Timer1 As Timer
'Declare a ready state flag
Private m_ReadyState As Boolean
Private Sub PDFCreator_Ready() Handles m_PDFCreator.eReady
MessageBox.Show("Printed doc")
Me.m_PDFCreator.cPrinterStop = True
Me.m_ReadyState = True
End Sub
Private Sub PDFCreatorError() Handles m_PDFCreator.eError
Me.m_PDFError = Me.m_PDFCreator.cError
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles m_Timer1.Tick
Me.m_Timer1.Enabled = False
End Sub
Public Sub CreatePDF(ByVal filename As String)
'Initialise the pdf creator and pdf error objects
Me.m_PDFError = New PDFCreator.clsPDFCreatorError
Me.m_PDFCreator = New PDFCreator.clsPDFCreator
If Me.m_PDFCreator.cStart("/NoProcessingAtStartup") = False Then
MessageBox.Show("Status: Error[" & Me.m_PDFError.Number & "]: " & Me.m_PDFError.Description)
End If
'Initialise the timer
Me.m_Timer1 = New Timer
'Declare a pdf creator options object
Dim pdfOptions As New PDFCreator.clsPDFCreatorOptions
'Declare a string to hold the name of the default printer
Dim strDefaultPrinter As String
'Check that the file exists
If System.IO.File.Exists(filename) Then
'Check that the file is printable
If Not Me.m_PDFCreator.cIsPrintable(filename) Then
Throw New System.ArgumentException( _
"The file " & filename & " is not printable to pdf.")
Exit Sub
End If
'Set the pdf options object to reference the pdf creator options
pdfOptions = Me.m_PDFCreator.cOptions
'Set the values of the options
With pdfOptions
'Set the autosave
.UseAutosave = 1
.UseAutosaveDirectory = 1
.AutosaveDirectory = System.IO.Path.GetDirectoryName(filename)
.AutosaveFilename = System.IO.Path.GetFileName(filename).Replace(".xmcd", "")
.AutosaveFormat = 0
End With
'Set some of the pdf creator properties
With Me.m_PDFCreator
.cOptions = pdfOptions
.cClearCache()
strDefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
.cPrintFile(filename)
.cPrinterStop = False
End With
'Set the readystate
Me.m_readyState = False
'Run through the timer
With Me.m_Timer1
.Interval = 20 * 1000
.Enabled = True
Do While Not m_ReadyState And .Enabled
Application.DoEvents()
Loop
.Enabled = False
End With
If Not Me.m_ReadyState Then
MessageBox.Show("An error has occured: Time is up", "Time Out", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Me.m_PDFCreator.cPrinterStop = True
Me.m_PDFCreator.cDefaultPrinter = strDefaultPrinter
Me.m_PDFCreator.cClose()
End If
End Sub