PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 16, 2024 10:57 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Word Docs To PDF
PostPosted: Wed Dec 06, 2006 12:48 pm 
Offline

Joined: Wed Dec 06, 2006 12:46 pm
Posts: 1
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!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 07, 2006 8:56 pm 
Offline
User avatar

Joined: Wed Nov 08, 2006 11:23 am
Posts: 4
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: Word Docs To PDF
PostPosted: Tue Feb 24, 2015 11:19 am 
Offline

Joined: Tue Feb 24, 2015 11:03 am
Posts: 1
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 141 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group