umon
umon

Reputation: 245

to save docx as pdf in c# (.net) with policy label

i'm converting .docx files to .pdf with Microsoft.Office.Interop.Word library in C# (.Net Framework 4.6.2)

my code is:

    public static void DOCtoPDF(string docFullPath, string pdfFullPath)
    {
        Application appWord = new Application();
        var wordDocument = appWord.Documents.Open(docFullPath);

        wordDocument.SaveAs2(pdfFullPath, WdSaveFormat.wdFormatPDF);
        wordDocument.Close();
        appWord.Quit();
    }

i'm taking this error while i am saving doc file:

enter image description here

how to solve this problem?

Upvotes: 3

Views: 5350

Answers (2)

umon
umon

Reputation: 245

I solved my problem..

it's trying to save wordDocument so it show me that dialog..

i wrote

wordDocument.Close(false);

instead of

wordDocument.Close();

now, it is not trying to save my original word document. it only convert to pdf. :)

Upvotes: 2

bellpatricia
bellpatricia

Reputation: 49

As an alternative approach to Microsoft.Office.Interop.Word library, you may want to check out GemBox.Document library.

For example like this:

public static void DOCtoPDF(string docFullPath, string pdfFullPath)
{
    DocumentModel wordDocument = DocumentModel.Load(docFullPath);
    wordDocument.Save(pdfFullPath);
}

Upvotes: 2

Related Questions