×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Using the API to print to pdf

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?

RE: Using the API to print to pdf

You shouldn't need to change the default printer.  You ought to be able to change the SELECTED printer, just as you would if you were doing it manually.

TTFN



RE: Using the API to print to pdf

(OP)
There is no option in the api to select a printer.

RE: Using the API to print to pdf

(OP)
I found a way to print to pdf using pdfCreator

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources