iTextSharp.LGPLv2.Core 如何将word转换成pdf
时间: 2024-01-29 10:44:06 浏览: 26
您可以使用iTextSharp.LGPLv2.Core将Word文档转换为PDF格式。以下是一个简单的示例代码:
```
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
// Create a document object
Document doc = new Document();
// Create a PDF writer
PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create));
// Open the document
doc.Open();
// Create a Word document object
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wordDoc = null;
// Open your Word document
wordDoc = word.Documents.Open("input.docx");
// Insert the content of the Word document into the PDF
doc.Add(new Paragraph(wordDoc.Content.Text));
// Close the Word document
wordDoc.Close(false);
// Close the document
doc.Close();
```
请注意,您需要安装Microsoft.Office.Interop.Word以便在代码中使用Word对象。另外,iTextSharp.LGPLv2.Core是基于LGPLv2许可的开源PDF库,您需要遵循该许可证来使用它。