在.NET中生成PDF文件 [英] Generating PDF file in .NET

查看:116
本文介绍了在.NET中生成PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#.NET 2.0.我想生成一个PDF文件.我应该在文件中写一个文本.

I am using C# .NET 2.0.I want to generate a PDF file . I should write a text in the file.

生成PDF需要哪些先决条件.

What are the prerequsites we need to generate the PDF.

任何simplae编码示例都会对我有帮助.

Any simplae coding samples will help me.

请推荐开源库.

谢谢.

推荐答案

使用 PDFSharp

PDFsharp是一个开放源代码库,可以轻松地从任何.NET语言创建PDF文档. 相同的绘图例程可用于创建PDF文档,在屏幕上绘图或将输出发送到任何打印机.

PDFsharp is the Open Source library that easily creates PDF documents from any .NET language. The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer.

// Create a new PDF document
PdfDocument document = new PdfDocument();

// Create an empty page
PdfPage page = document.AddPage();

// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);

// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);

// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height),
  XStringFormat.Center);

// Save the document...
string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);

样品

这篇关于在.NET中生成PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆