我正在尝试使用 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 而不会丢失文本文件的格式,有人有什么建议吗? 感谢您的帮助。
最佳答案
我建议让您的 PDF 文件使用像 Courier New 这样的等宽字体。
关于c# - 尝试在不丢失格式的情况下将纯文本文件转换为 iTextSharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988034/