Click here to Skip to main content
15,886,110 members

Comments by kumarbl (Top 2 by date)

kumarbl 11-Apr-12 6:29am View    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;

namespace SaveWordAsPDF
{
class Program
{
static void Main(string[] args)
{
object visible = true;
object readOnly = true;
object sourceFilename;
string targetFilename;
Application wordApp = new Application();
sourceFilename = "D:\\dartword\\MyDocument2.docx";
targetFilename = "D:\\dartword\\MyDocument.pdf";
Document doc = wordApp.Documents.Open(ref sourceFilename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref visible, ref missing, ref missing,
ref missing, ref missing);

doc.ExportAsFixedFormat(targetFilename, WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForOnScreen,
WdExportRange.wdExportAllDocument, 0, 0, WdExportItem.wdExportDocumentContent, false, false,
WdExportCreateBookmarks.wdExportCreateNoBookmarks, false, false, false, ref missing);

object saveChanges = false;
doc.Close(ref saveChanges, ref missing, ref missing);
wordApp.Quit(ref saveChanges, ref missing, ref missing);
}

static object missing = Type.Missing;
}
}
kumarbl 11-Apr-12 6:28am View    
Hi ramlinga koushik,
I have copy the same as your code, if i tried to run it showing the below error:


Attempted to read or write protected memory. This is often an indication that other memory is corrupt.