PDF for .NET
ドキュメントの作成

To create PDF documents using PDF for .NET, you simply create a C1PdfDocument object, add content to the document, and save the document. To follow tradition, here's how to create a "hello world" document using PDF for .NET.

  1. Add the following Imports or using directive to your code.
    Imports System.Drawing
    
    using System.Drawing;
    
  2. Create a C1PdfDocument object.
    ' C1PdfDocument オブジェクトを作成します
    Dim pdf As New C1.C1Pdf.C1PdfDocument()
    
    // C1PdfDocument オブジェクトを作成します
    C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();
    
  3. Add your content to the Form_Load event. This usually involves calling the DrawString method.
    ' ページにコンテンツを追加します。
    Dim rect As RectangleF =  pdf.PageRectangle
    rect.Inflate(-72, -72)
    Dim font As Font =  New Font("Arial",12)
    pdf.DrawString("Hello World!", font, Brushes.Black, rect)
    
    // ページにコンテンツを追加します。
    RectangleF rect = pdf.PageRectangle;
    rect.Inflate(-72, -72);
    Font font = new Font("Arial", 12);
    pdf.DrawString("Hello World!", font, Brushes.Black, rect);
    
  4. Save the document to a file or to a stream using the Save method.
    ' ドキュメントをファイルに保存します
    pdf.Save(@"C:\PDF\Hello_World.pdf")
    
    // ドキュメントをファイルに保存します
    pdf.Save(@"C:\PDF\Hello_World.pdf");
    

After the application is run, the hello world.pdf document will look like this:


Step 3 is the most interesting one. The code starts by retrieving the page rectangle, expressed in points. It then adds a one-inch margin around the page (72 points). Finally, the code creates a Font object and calls the DrawString method to write "Hello World!" on the page. This is exactly what you would do if you were writing to a Graphics object in .NET and is what makes PDF for .NET so easy to use.

One important thing to remember is that PDF for .NET uses a point-based coordinate system with the origin at the top-left corner of the page. This is similar to the default coordinate system used by .NET, but is different from the default PDF coordinate system (where the origin is on the bottom-left corner of the page). In this example, the top left point of the "H" in "Hello World" is located at [1,1].

Because the coordinate system is based on points, rather than pixels, PDF for .NET uses RectangleF, SizeF, and PointF structures, which have members of type float, rather than Rectangle, Size, and Point, which have members of type int.