converting word to pdf using c#
Can anybody help me with a code to convert a word file pdf
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dorothy TincherPosted May 15, 2014, 4:06 AM
If not, than you can try combining an OpenXML SDK and iTextSharp, I tried this once but unfortunately the result was not satisfying.
You can also try this Word component in C#, I used it in quite a few scenarios and tasks that required a DOCX manipulations in .NET and I must say it is easy to work with.
For example here is a direct way you can convert your Word document into a PDF file in .NET:
rebecca yangPosted Sep 5, 2013, 11:45 PM
2. Save Word document as PDF by using document.SaveToFile() method. Parameters passed to this method is file name string and file format. The file format must be PDF.
You can download spire.DOC here :http://netword.codeplex.com/
C#
using System;
using Spire.Doc;
using Spire.Doc.Documents; namespace DoctoPDF
{
class toPDF
{
static void Main(string[] args)
{ //Load Document
Document document = new Document();
document.LoadFromFile(@"E:\work\documents\TestSample.docx");
//Convert Word to PDF
document.SaveToFile("toPDF.PDF", FileFormat.PDF);
//Launch Document
System.Diagnostics.Process.Start("toPDF.PDF");
}
}
}
{Visual Basic]
Imports System
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace DoctoPDF
Friend Class toPDF
Shared Sub Main(ByVal args() As String)
'Load Document
Dim document As New Document()
document.LoadFromFile("E:\work\documents\TestSample.docx")
'Convert Word to PDF
document.SaveToFile("toPDF.PDF", FileFormat.PDF)
'Launch Document
System.Diagnostics.Process.Start("toPDF.PDF")
End Sub
End Class
End Namespace
David IsaacPosted Jun 20, 2007, 9:34 AM
(using Microsoft.Office.Interop.Word;)
ApplicationClass wordApp = new ApplicationClass(); Document wordDoc = null; string paramExportFilePath = @"C:\\Test.xps";
WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatXPS;
bool paramOpenAfterExport = false;WdExportOptimizeFor paramExportOptimizeFor =
WdExportOptimizeFor.wdExportOptimizeForPrint;
WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
int paramStartPage = 0; int paramEndPage = 0;WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true; bool paramKeepIRM = true;WdExportCreateBookmarks paramCreateBookmarks
bool paramDocStructureTags = true; bool paramBitmapMissingFonts = true; bool paramUseISO19005_1 = false; try= WdExportCreateBookmarks.wdExportCreateWordBookmarks;
{
// Open the source document.wordDoc = wordApp.Documents.Open(
ref paramSourceDocPath, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing, ref paramMissing); // Export it in the specified format. if (wordDoc != null)wordDoc.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat, paramOpenAfterExport,
paramExportOptimizeFor, paramExportRange, paramStartPage,
paramEndPage, paramExportItem, paramIncludeDocProps,
paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
paramBitmapMissingFonts, paramUseISO19005_1,
ref paramMissing);}
catch (Exception ex){
// Respond to the error}
finally{
// Close and release the Document object. if (wordDoc != null){
wordDoc.Close(
ref paramMissing, ref paramMissing, ref paramMissing);wordDoc =
null;}
// Quit Word and release the ApplicationClass object. if (wordApp != null){
wordApp.Quit(
ref paramMissing, ref paramMissing, ref paramMissing);wordApp =
null;}
GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers();Mahesh ChandPosted Jun 20, 2007, 8:06 AM