0

所以我有我的基本 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);

用它??

4

1 回答 1

0

使用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()行为类似于Graphics.DrawString().NET

于 2013-07-18T20:03:15.200 回答