Домой Office Word to PDF C# : Справочник по C#

Word to PDF C# : Справочник по C#

748
0


//using Word = Microsoft.Office.Interop.Word;

Microsoft.Office.Interop.Word.Application _Word = new Microsoft.Office.Interop.Word.Application();
object _MissingValue = System.Reflection.Missing.Value;

private void simpleButton1_Click(object sender, EventArgs e)
{
_Word.Visible = false;
_Word.ScreenUpdating = false;

// Cast as Object for word Open method
string pathfile = @"D:MyWord.doc";
object filename = (object)pathfile;

// Use the dummy value as a placeholder for optional arguments
Word.Document doc = _Word.Documents.Open(ref filename, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);
doc.Activate();

object outputFileName = System.IO.Path.ChangeExtension(pathfile, "pdf");
object fileFormat = Word.WdSaveFormat.wdFormatPDF;

// Save document into PDF Format
doc.SaveAs(ref outputFileName,
ref fileFormat, ref _MissingValue, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue,
ref _MissingValue, ref _MissingValue, ref _MissingValue, ref _MissingValue);

// Close the Word document, but leave the Word application open.
// doc has to be cast to type _Document so that it will find the
// correct Close method.
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
((Word._Document)doc).Close(ref saveChanges, ref _MissingValue, ref _MissingValue);
doc = null;

// word has to be cast to type _Application so that it will find
// the correct Quit method.
((Word._Application)_Word).Quit(ref _MissingValue, ref _MissingValue, ref _MissingValue);
_Word = null;
}

ЧИТАТЬ ТАКЖЕ:  Чтение ARP таблицы с использованием WinAPI: Справочник по C#

Word to PDF C# : Справочник по C#

0.00 (0%) 0 votes

ОСТАВЬТЕ ОТВЕТ

Пожалуйста, введите ваш комментарий!
пожалуйста, введите ваше имя здесь