C# 将e.DrawString与iTextSharp一起使用以另存为.pdf
所以我有我的基本iTextSharp代码C# 将e.DrawString与iTextSharp一起使用以另存为.pdf,c#,pdf,itextsharp,C#,Pdf,Itextsharp,所以我有我的基本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", Fil
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,笔刷,黑色,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()
我不这么认为。iTextSharp是你必须的吗?如果不是,那么PDfSharp将是做类似事情的好选择。如果你想做,请通知我。@ridoy iTextSharp不是必须的。我可以在PDFSharp中使用e.Graphics.DrawString吗?您的问题是“如何将WinForms标签的内容写入PDF?”我如何使用此选项来删除标签或文本框?您想绘制文本框/标签还是其文本?请明确说明你想做什么?我有一个带有标签和文本框的windows窗体。我在打印文档中使用了e.Graphics.DrawString和e.Graphics.draw矩形,但现在我想将其另存为pdf。我知道我可以使用像Bullzip PDF printer这样的程序,但我希望它对最终用户更简单。因此,您希望将windows窗体打印为PDF格式,所有内容都在一个词中?是的,但不是打印屏幕。我有一些if语句,比如:if(textBox72.Text==“0”&&textBox80.Text==“0”&&textBox40.Text==“0”。。。。。。。