PDF In-Depth

IAC - How to convert Excel Chart to PDF using PDFWriter

May 22, 2000

Advertisement
Advertisement
 

A VB program that automatically converts Excel Charts to PDF Format. A file list of Excel Charts, and a file list of the pdf names is required.

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.


Private
 Sub
 Form_Load(
)
'
'   This program converts EXCEL format charts to PDF
'   format (WIN-NT). It reads in a list of file names from a file
'   and then converts those files to PDF format. It also
'   edits the _pdf.ini file to allow this task to take place
'
'   This program reads in a list of EXCEL file names from a file
'   into an array. It also reads the corresponding list of pdf files
'   into another array. The file order and names are the same, except for the
'   file extenstion.
'   It removes any files with a ".old" extension. It then renames
'   the original PDF files with the extension ".old", and creates the
'   new odf files.
'
'On Error Resume Next        ' Just ignore any files that are not found
Dim
 XA As
 Application       ' EXCEL Application
Dim
 XC As
 Workbook          ' EXCEL Workbook
Dim
 CurrentLine As
 String
   ' Hold the .xls file name
Dim
 pdfformat As
 String
     ' Hold the .pdf file name
Dim
 Count As
 Integer
        ' Counter for array
Dim
 OldName,
 NewName        ' Change names of converted files.
Set
 XA = Excel.
Application  'Set up Excel Application in VB
Dim
 PDFFilename As
 String
   'To hold the pdf generated file name
Dim
 PDFView As
 BooleanDim
 i As
 Integer
            'used when opening _pdf.ini
PDFFilename = "c:\xlsfiles\file.pdf"    'file & path name for the pdf
generated file
'Kill "c:\xlsfiles\testing\*.old"     'Delete all the old pdf files
i = 1                            ' size of array for the pdf files
pdfarraysize = FileLen(
"c:\xlsfiles\pdflist.txt")
ReDim
 pdfArray(
pdfarraysize)
    'declare array for reading in PDF files
ReDim
 pdfArrayold(
pdfarraysize)
 'delclare array for renaming pdf files
Open
 "c:\xlsfiles\pdflist.txt" For
 Input
 As
 #2      'open file for input
Cntr = 0Do
 While
 Not EOF(
2)
 ' Check for end of file, this file is the same as #2
only extensions are different.    Line
 Input
 #2,
 pdfformat
    pdfArray(
Cntr)
 = pdfformat                      'read file names into array    pdfArrayold(
Cntr)
 = pdfformat & ".old"          ' read file names
in, adding .old extension    OldName = pdfArray(
Cntr)
: NewName = pdfArrayold(
Cntr)    'Name OldName As NewName ' Move and rename file. 'renaming original
pdf file with .old    Cntr = Cntr + 1Loop
'
'   Update the __pdf.ini file
'
'   The variables can be set to anything you want. These are just the
values'   I had in the original .ini file
'
Open
 "C:\WINNT\System32\Spool\Drivers\W32x86\2\__pdf.ini" For
 Output Asi

Print
 #i,
 "[Acrobat PDFWriter]"Print
 #i,
 "ErrFlag = 0"Print
 #i,
 "szTitle = file.PDF"Print
 #i,
 "szAuthor = adaly01"Print
 #i,
 "szProducer=Acrobat PDFWriter 3.03 for Windows NT"Print
 #i,
 "szCreator = Project1 - Microsoft; Visual; Basic; [run] -
[Form1 (Code)]"Print
 #i,
 "szDate=D:19990121102130"Print
 #i,
 "startDocTitle = file.xls"Print
 #i,
 "FileNameSet = 0"Print
 #i,
 "szSubject="Print
 #i,
 "szKeywords="Print
 #i,
 "orient = 2"Print
 #i,
 "bDocInfo=0"
If
 PDFView = True
 Then
 Print
 #i,
 "bExecViewer = 1"
Close
 i

InstallarraySize = FileLen(
"c:\xlsfiles\list.txt")
  'get size of EXCEL
(
extentsion)
file
ReDim
 InstallArray(
InstallarraySize)
Open
 "c:\xlsfiles\list.txt" For
 Input
 As
 #1 'open file for input
Do
 While
 Not EOF(
1)
                 ' Check for end of file
    Line
 Input
 #1,
 CurrentLine      ' Read line of data.
    InstallArray(
Count)
 = CurrentLine
    Set
 XC = XA.
Workbooks.
Open
(
InstallArray(
Count)
)                                    ' Print each worksheet to the PDF
writer
    For
 Each
 ws In
 Worksheets       ' The file created is "c:\xlsfiles\file.pdf
        Sheets(
"BAC_chart")
.
PrintOut
        
        'Sheets.PrintOut
        Next
 ws
    
    OldName = PDFFilename: NewName = pdfArray(
Count)    'Name OldName As NewName         ' Move and rename file.
    Count = Count + 1Loop
XA.
Workbooks.
Close
                  ' Close any workbooks
Close
 #1                            ' Close "c:\xlsfiles\list.txt"
Close
 #2                            ' Close "c:\xlsfiles\pdflist.txt"

Kill
 "C:\WINNT\System32\Spool\Drivers\W32x86\2\__pdf.ini"
Unload
 Me
                           ' Closes the form
End
 Sub
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.