• Print To Picture Using PDFCreator

    This article contains code examples to print worksheets to PDF files in a picture format, including: pdf, png, jpg, bmp, pcx, tif, ps (postscript), eps and txt.

    This code example is built for PDFCreator, an open source PDF writer utility. Unlike Adobe Acrobat and CutePDF, which both require pro versions to create PDF's via code, PDFCreator is completely free! Download PDF Creator from Sourceforge here. Please note that this code will NOT work with Adobe Acrobat.

    It should also be noted that each of the examples in this section use an Early Bind. If you are not familiar with the difference between Early and Late Binding, please read our article on Early vs Late binding.

    Versions Tested:
    These routines were tested successfully using PDFCreator 0.9.1, GPLGhostscript.exe download package, on Windows XP Pro (SP2). Excel versions tested include:
    • Excel 2003
    • Excel 2007

    Code Required:
    This code goes in a standard module.

    Sub PrintToPDFCreator_Early()
    'Author       : Ken Puls (www.excelguru.ca)
    'Macro Purpose: Print to Output file using PDFCreator
    '   (Download from http://sourceforge.net/projects/pdfcreator/)
    '   Designed for early bind, set reference to PDFCreator
        Dim OutputJob As PDFCreator.clsPDFCreator
        Dim sOutputName As String
        Dim sOutputPath As String
        Dim lOutputType As Long
        '/// Change the output file name and type here! ///
        sOutputName = "test"
        '0=PDF, 1=Png, 2=jpg, 3=bmp, 4=pcx, 5=tif, 6=ps, 7=eps, 8=txt
        lOutputType = 2
        sOutputPath = ActiveWorkbook.Path & Application.PathSeparator
        Set OutputJob = New PDFCreator.clsPDFCreator
        'Set correct filename extension
        Select Case lOutputType
            Case Is = 0
                sOutputName = sOutputName & ".pdf"
            Case Is = 1
                sOutputName = sOutputName & ".png"
            Case Is = 2
                sOutputName = sOutputName & ".jpg"
            Case Is = 3
                sOutputName = sOutputName & ".bmp"
            Case Is = 4
                sOutputName = sOutputName & ".pcx"
            Case Is = 5
                sOutputName = sOutputName & ".tif"
            Case Is = 6
                sOutputName = sOutputName & ".ps"
            Case Is = 7
                sOutputName = sOutputName & ".eps"
            Case Is = 8
                sOutputName = sOutputName & ".txt"
        End Select
        'Set job defaults
        With OutputJob
            If .cStart("/NoProcessingAtStartup") = False Then
                MsgBox "Can't initialize PDFCreator.", vbCritical + _
                        vbOKOnly, "PrtPDFCreator"
                Exit Sub
            End If
            .cOption("UseAutosave") = 1
            .cOption("UseAutosaveDirectory") = 1
            .cOption("AutosaveDirectory") = sOutputPath
            .cOption("AutosaveFilename") = sOutputName
            .cOption("AutosaveFormat") = lOutputType
        End With
        'Print the document to PDF
        ActiveWorkbook.PrintOut copies:=1, ActivePrinter:="PDFCreator"
        'Wait until the print job has entered the print queue
        Do Until OutputJob.cCountOfPrintjobs = 1
        OutputJob.cPrinterStop = False
        'Wait until PDF creator is finished then release the objects
        Do Until OutputJob.cCountOfPrintjobs = 0
        Set OutputJob = Nothing
    End Sub


    I'm afraid that you must be logged in to comment or leave a testimonial. I wish it could be otherwise, but I'm trying to keep my site spam free for everyone's benefit. If you don't yet have an account it's completely free to sign up, and a very quick process. Simply click here to Register. Not only can you post a comment here, but it gives you full access to posts questions in our forum as well!


    If you already have an account, and just haven't logged in yet, what are you waiting for? Login Now!

  • MVP Logo
  • Recent Forum Posts

    Bob Phillips

    Please help!

    This array formula will add up the sums


    Bob Phillips Today, 08:46 PM Go to last post
    Bob Phillips

    Index/match with multiple match criteria

    When I said Q1, I meant Quarter 1, cell E31, not cell Q1.

    It most definitely does match your last upload, C8:C30 is the date which I parse,...

    Bob Phillips Yesterday, 06:44 PM Go to last post

    Consolidate paired data sets

    hi all,

    I have a sheet which contains data sets (3 rows per data set), see Product Level sheet of attachment. I want to consolidate and total...

    GLewis14 Yesterday, 02:46 PM Go to last post

    Please help!

    What is the criteria for counting the quantity. Would be helpful if you provided a sample workbook showing what you have and what your expected results...

    alansidman Yesterday, 06:21 AM Go to last post

    Please help!

    I am trying to count two separate pieces of data which appear in the same excel column. The columns will have a date followed by a quantity so look something...

    cprop76 Yesterday, 05:52 AM Go to last post