Converting Excel Spreadsheets to PDF for Visual Basic.NET
'----------------------------------------------------------------------
' 1) Microsoft Excel 97 or above should be installed and activated on your PC.
'
' 2) Universal Document Converter 5.2 or above should be installed, too.
'
' 3) Open your project in Microsoft Visual Basic.NET.
'
' 4) In Visual Basic main menu press "Project->Add Reference...".
'
' 5) In "Add Reference" window go to "COM" tab and double click into
' "Universal Document Converter Type Library".
'
' 6) Before using this example, please read this article from Microsoft Excel 2003 knowledge base:
' http://support.microsoft.com/kb/320369/en-us/
'----------------------------------------------------------------------Private Sub PrintExcelToPDF(ByVal strFilePath As String)
Dim objUDC As UDC.IUDC
Dim itfPrinter As UDC.IUDCPrinter
Dim itfProfile As UDC.IProfile
Dim objXLApp As ObjectDim itfXLBook As ObjectDim itfXLWorksheet As ObjectDim itfXLPageSetup As Object
objUDC = New UDC.APIWrapper
itfPrinter = objUDC.Printers("Universal Document Converter")
itfProfile = itfPrinter.Profile
' Use Universal Document Converter API to change settings of converterd document
itfProfile.PageSetup.FormName = "A2"
itfProfile.PageSetup.ResolutionX = 200
itfProfile.PageSetup.ResolutionY = 200
itfProfile.PageSetup.Orientation = UDC.PageOrientationID.PO_LANDSCAPE
itfProfile.FileFormat.ActualFormat = UDC.FormatID.FMT_PDF
itfProfile.FileFormat.PDF.ColorSpace = UDC.ColorSpaceID.CS_TRUECOLOR
itfProfile.FileFormat.PDF.Multipage = UDC.MultipageModeID.MM_MULTI
itfProfile.Adjustments.Crop.Mode = UDC.CropModeID.CRP_AUTO
itfProfile.OutputLocation.Mode = UDC.LocationModeID.LM_PREDEFINED
itfProfile.OutputLocation.FolderPath = "C:\Out"
itfProfile.OutputLocation.FileName = "&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]"
itfProfile.OutputLocation.OverwriteExistingFile = False ' Run Microsoft Excle as COM-serverOn Error Resume Next
objXLApp = CreateObject("Excel.Application")
' Open spreadsheet from file
itfXLBook = objXLApp.Workbooks.Open(strFilePath, , True)
' Change active worksheet settings and print it
itfXLWorksheet = itfXLBook.ActiveSheet
itfXLPageSetup = itfXLWorksheet.PageSetup
itfXLPageSetup.Orientation = 2 ' LandscapeCall itfXLWorksheet.PrintOut(, , , False, "Universal Document Converter")
' Close the spreadsheetCall itfXLBook.Close(False)
itfXLBook = Nothing
' Close Microsoft ExcelCall objXLApp.Quit()
objXLApp = Nothing
End Sub