Search code examples
c#asp.netpdfoffice-interop

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?


Solution

  • 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. :)