PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Word Docs To PDF https://forum.pdfsharp.net/viewtopic.php?f=2&t=36 |
Page 1 of 1 |
Author: | jediwi [ Wed Dec 06, 2006 12:48 pm ] |
Post subject: | Word Docs To PDF |
Being new to PDFSharp, I need to know how to load a Word document and convert it to a PDF file. Can someone please provide a code sample for doing this? Thanks! |
Author: | QuoVadis [ Thu Dec 07, 2006 8:56 pm ] |
Post subject: | |
You have to use the COM-Api of Microsoft Word to print the document on a PostScript printer, redirect the output to a file (with RedMon or the COM-Api) and convert the PostScript file to a PDF (with Ghostscript or the GS wrapper of PDFSharp). |
Author: | ollie [ Tue Feb 24, 2015 11:19 am ] |
Post subject: | Re: Word Docs To PDF |
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 |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |