从 VB.NET 中的 dotx 文件生成 pdf 文件

Generate pdf file from dotx file in VB.NET

我可以使用 vb.net 从 dotx 文件创建一个 docx 文件。但是,我需要此 dotx 文件模板中的 pdf 文件。我试图通过将自身另存为 pdf 从 MS Office Word 创建一个 pdf 文件,我希望它也可以通过在 vb.net

中编码来完成
Imports Word = Microsoft.Office.Interop.Word

Public Class frmWordTemplate
    Private wdApp As Word.Application
    Private wdDocs As Word.Documents
    Const sPath As String = "D:\"
    Private sFileName As String

    Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click

        sFileName = "export-file"

        wdApp = New Word.Application

        wdDocs = wdApp.Documents

        Dim wdDoc As Word.Document = wdDocs.Add(sPath & "template_sample.dotx")
        Dim wdBooks As Word.Bookmarks = wdDoc.Bookmarks

        wdBooks("bkClient_name").Range.Text = txtClient.Text.ToString
        wdBooks("bkDate").Range.Text = dtpDate.Text.ToString


        wdDoc.SaveAs2(sPath & sFileName & ".docx")

        ReleaseObject(wdBooks)
        wdDoc.Close(False)
        ReleaseObject(wdDoc)
        ReleaseObject(wdDocs)
        wdApp.Quit()

在保存中添加文件格式

wdDoc.SaveAs2(sPath & sFileName & ".pdf", Word.WdSaveFormat.wdFormatPDF)

任务完成!