PDF for .NET
画像の描画

Adding images to PDF for .NET documents is also easy, all the work is done by the DrawImage method.

DrawImage draws a given image at a specified location and has parameters that provide control over the image alignment and scaling. In the following example, this image is:

This code is used to draw the same image three times:

To write code in Visual Basic

Visual Basic
コードのコピー
Dim rect As RectangleF = pdf.PageRectangle
rect.Inflate(- 72, - 72)
 ' 四角形に合わせて画像を引き伸ばします。
pdf.DrawImage(pictureBox1.Image, rect) ' 画像を四角形の中央に配置し、縦横比を維持しながらスケーリングします。
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.MiddleCenter, C1.C1Pdf.ImageSizeMode.Scale)
 ' 画像を四角形の左上に描画します。
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.TopLeft, C1.C1Pdf.ImageSizeMode.Clip)

To write code in C#

C#
コードのコピー
RectangleF rect = pdf.PageRectangle;
rect.Inflate(-72, -72);
 // 四角形に合わせて画像を引き伸ばします。
pdf.DrawImage(pictureBox1.Image, rect); // 画像を四角形の中央に配置し、縦横比を維持しながらスケーリングします。
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.MiddleCenter, C1.C1Pdf.ImageSizeMode.Scale); // 画像を四角形の左上に描画します。
pdf.DrawImage(pictureBox1.Image, rect, ContentAlignment.TopLeft, 1.C1Pdf.ImageSizeMode.Clip);

The PDF document will look similar to this:


Notice that you can render any regular .NET Image object, including Metafiles. Metafiles are not converted into bitmaps; they are played into the document and thus retain the best possible resolution. If you want to add charts or technical drawings to your PDF document, Metafiles are better than bitmap images. PDF for .NET also supports EMF+ metafiles.

Bitmap images are managed automatically by PDF for .NET. If you render the same image several times (in a page header for example), only one copy of the image is saved into the PDF file. You can control the quality of the images using the C1PdfDocumentBase.ImageQuality property, which allows you to trade-off image quality versus file size.