【发布时间】:2018-05-31 05:53:09
【问题描述】:
我在 VB 中有一个控制台应用程序。 今天我使用 PDFsharp (http://www.pdfsharp.net/) 来合并 PDF 文件 像这样:
Private Sub mergePdfFiles(pdfFiles As String(), output As String)
Dim out As PdfDocument = New PdfDocument
Try
For Each file As String In pdfFiles
Dim inputDoc As PdfDocument = PdfSharp.Pdf.IO.PdfReader.Open(file,IO.PdfDocumentOpenMode.Import)
Dim count As Integer = inputDoc.PageCount
For idx As Integer = 0 To count - 1
Dim page As PdfPage = inputDoc.Pages(idx)
out.AddPage(page)
Next
Next
out.Save(output)
Catch ex As Exception
End Try
End Sub
这很好用。 现在我想将 DOCX 文件转换为 PDF,但似乎 PDFsharp 做不到。 我知道MigraDoc可以做到
MigraDoc Foundation 开源 .NET 库,可轻松创建基于具有段落、表格、样式等的对象模型的文档,并将它们呈现为 PDF 或 RTF。
但我没能做到。示例不是很清楚,适用于 C#。 http://www.pdfsharp.net/wiki/DocumentViewer-sample.ashx
例如:
//create RTF file From document
private void miRtf_Click(object sender, System.EventArgs e)
{
RtfDocumentRenderer rtf = new RtfDocumentRenderer();
rtf.Render(this.pagePreview.Document, "test.rtf", null);
Process.Start("test.rtf");
}
在 VB 中,我尝试使用 Me 而不是 this,但我没有 pagePreview。
如何在 VB 中使用 MigraDoc 或 PDFsharp 将 DOCX 文件转换为 PDF 文件?
【问题讨论】:
标签: c# vb.net converter pdfsharp migradoc