Do you have an example of this code? I did something like this with the PDF creator COM object model but now I need to change to a new product and would like to know if I can do this with PDF sharp.
Here's what I used for PDFCreator :
Code:
Function PDFConvert()
On Error Resume Next
Dim PDFCreator1
Dim DefaultPrinter
Dim InFile
Dim OutputFilename
Dim tempFile
Dim objExcel
Dim fso
Dim blnExcelOpen
Dim blnFileOpen
Dim blnCreatorOpen
Const PrinterName = "PDFCreator"
InFile = "C:\temp\SFP\Plan_DANA_2014-0008.xlsx"
OutputFilename = "C:\temp\SFP\Plan_DANA_2014-0008.PDF"
Set PDFCreator1 = CreateObject("PDFCreator.clsPDFCreator")
If Err.Number = 0 Then
'*creator ok
blnCreatorOpen = vbTrue
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(InFile) Then
'*file exists
tempFile = fso.GetParentFolderName(InFile) & "\"
tempFile = tempFile & "TEMP_SPOOL"
Set objExcel = CreateObject("Excel.Application")
If Err.Number = 0 Then
'*Excel ok
blnExcelOpen = vbTrue
objExcel.Visible = False
objExcel.Workbooks.Open InFile
If Err.Number = 0 Then
'*excel workbook open
'*TODO 10.2.2015 Error 1004 Impossible de définir la propriété ActivePrinter de la classe Application.
blnFileOpen = vbTrue
DefaultPrinter = objExcel.ActivePrinter
objExcel.ActivePrinter = PrinterName
objExcel.ActiveSheet.PrintOut 1, 1, , , , True, , tempFile
PDFCreator1.cStart "/NoProcessingAtStartup"
PDFCreator1.cConvertFile tempFile, OutputFilename
objExcel.ActivePrinter = DefaultPrinter
Else
'*doc open error
MsgBox Err.Description
PDFConvert = 4
End If
Else
'*Excel error
MsgBox Err.Description
PDFConvert = 3
End If
Else
'*no in file
MsgBox Err.Description
PDFConvert = 2
End If
Else
'* creator not ok
MsgBox Err.Description
PDFConvert = 1
End If
'*Cleanup
If blnFileOpen = vbTrue Then
objExcel.ActiveWorkbook.Close False
fso.DeleteFile (tempFile)
Set fso = Nothing
End If
If blnExcelOpen = vbTrue Then
objExcel.Quit
Set objExcel = Nothing
End If
If blnCreatorOpen = vbTrue Then
Set PDFCreator1 = Nothing
End If
End Function