i want to pragmatically convert office documents to pdf.i do not want to use the microsoft office service ddl. this is the code which i used,
using System;
using System.IO;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.IO.Compression;
using Document = Microsoft.Office.Interop.Word.Document;
namespace pdfconversion
{
public class PdfMerge
{
static void Main()
{
var wordApplication = new Microsoft.Office.Interop.Word.Application();
Document wordDocument = null;
object paramSourceDocPath = @"C:\testfile.doc";
object paramMissing = Type.Missing;
string paramExportFilePath = @"C:\Temp\Test1234.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 =
WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
try
{
// Open the source document.
wordDocument = wordApplication.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 (wordDocument != null)
wordDocument.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 (wordDocument != null)
{
wordDocument.Close(ref paramMissing, ref paramMissing,
ref paramMissing);
wordDocument = null;
}
// Quit Word and release the ApplicationClass object.
if (wordApplication != null)
{
wordApplication.Quit(ref paramMissing, ref paramMissing,
ref paramMissing);
wordApplication = null;
开发者_运维问答 }
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
i want to use a assembly not a com.does anyone know anything that might help me?i tried itextsharp.it does not do the converting. and cutepdf is not able to convert to pdf directly. please help me out with this.i have tried ghostscript. but it converts postscripts to pdf i couldn't find a way to convert office documents to .ps. is there any other free library which i can use to meet my requirement?
please help me out here thanx
Actually, the method I know is similar with you. But I found a simple method with 3rd party component from a blog post.
http://stephenchy520.blog.com/2011/11/24/how-to-convert-word-doc-to-pdf-for-cvb-net/
Maybe method in this post is helpful for you.
I've recently looked at lot of free softwares to convert documents to PDF and I must admit that none of them were meeting my requirements. Some converters were not bad but the licenses were to restrictive. I think you will have to find a good non free converter.
You can take a look a this list of PDF converters: Converters
I'd recommend automating Open Office to do the conversion. It's free, and in my experience far more stable than Microsoft Office when being used for automated conversion tasks.
See my answer on similar question here, which includes a code sample.
精彩评论