如何在C#.net中编写.PDF文件 [英] How to Write .PDF file In C#.net

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

问题描述

如何在c#.net中编写.pdf文件?

How to write .pdf file in c#.net?

推荐答案

PDfSharp或ITextSharp可以解决问题。


PdfSharp上的
是这样的:



PDfSharp or ITextSharp would do the trick.

on PdfSharp is like this:

class Program
  {
    static void Main(string[] args)
    {
   // Create a new PDF document
      PdfDocument document = new PdfDocument();
      document.Info.Title = "Created with PDFsharp";
 
      // 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.BoldItalic);
 
      // Draw the text
      gfx.DrawString("Hello, World!", font, XBrushes.Black,
        new XRect(0, 0, page.Width, page.Height),
        XStringFormats.Center);
 
      // Save the document...
      const string filename = "HelloWorld.pdf";
      document.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
    }
  } 




ITextSharp上的
是这样的:





on ITextSharp is like this:

iTextSharp.text.Document oDoc = new iTextSharp.text.Document();
PdfWriter.GetInstance(oDoc, new FileStream("HelloWorld.pdf", FileMode.Create));
oDoc.Open();
oDoc.Add(new Paragraph("Hello World!"));
oDoc.Close();





我已经使用过它们两者,并且必须说两者都很棒,但iTextSharp也可以将PDF渲染为图像(栅格化)。 PdfSharp也更快更小。



希望它有所帮助。



I have used them both, and must say both are great, but iTextSharp can also render a PDF to an image (rasterize). PdfSharp is faster and smaller also.

hope it helps.


PDFSharp [ ^ ]。好的图书馆将帮助您轻松创建PDF格式。
PDFSharp[^]. Nice library will help you create pdf easily.


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

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