[英]Using e.DrawString with iTextSharp to save as .pdf
所以我有基本的iTextSharp代码
private void button1_Click(object sender, EventArgs e)
{
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Test.pdf", FileMode.Create));
doc.Open();
doc.Add();
doc.Close();
}
现在我可以使用
e.Graphics.DrawString(label1.Text, label1.Font, Brushes.Black, 13, 13);
用它??
使用PdfDocument
您可以执行以下操作。
PdfDocument document = new PdfDocument();
document.Info.Title = "Sample pdf using PDFsharp";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic); //set your label1.Font here
gfx.DrawString("Sample using PdfSharp!", font, XBrushes.Black, //you can use your label1.Text here
new XRect(0, 0, page.Width, page.Height),
XStringFormats.Center);
const string filename = "sample.pdf";
document.Save(filename);
Process.Start(filename);
这里的XGraphics.DrawString()
就像.NET
Graphics.DrawString()
一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.