【发布时间】:2011-08-08 20:18:25
【问题描述】:
我正在尝试使用 iText Sharp 将文本文件转换为 PDF。 转换本身不是问题,但是,我无法创建 PDF 文件,使其看起来与文本文件中的文本完全对齐。
这是我正在使用的代码:
public void GetPDF(string data)
{
using (MemoryStream ms = new MemoryStream())
{
Rectangle docSize = new Rectangle(612, 798);
Document myDocument = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(myDocument, new FileStream
("MyNewPDF.pdf", FileMode.Create));
// step 3: Open the document now using
myDocument.Open();
// step 4: Now add some contents to the document
myDocument.Add(new Paragraph(data));
myDocument.Close();
}
}
是否有人建议如何将文本文件简单地转换为 PDF 而不会丢失文本文件的格式? 任何帮助表示赞赏。
【问题讨论】:
-
我对 MemoryStream
ms的用途有点困惑。 (或者是data在添加新段落时只是错误地命名了同一件事?)
标签: c# itextsharp