How to Insert an Image into a PDF

This samples shows how to use images in your PDF documents.
You can create an image from a file in GIF/TIFF/PNG/BMP/Jpeg formats, or a buffer of image bytes, or an System.Drawing.Image object.

C# :

using PDFMosaic;
using System.Drawing;

namespace DrawImage
{
  class DrawImage
  {
    static void Main(string[] args)
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
      PDFCanvas canvas = document.Pages[0].Canvas;
      PDFImage image = new PDFImage("..\\..\\two_pilots.bmp");
      canvas.DrawImage(image, 20, 50);
      canvas.DrawImage(image, image.Width + 20, 50, image.Width / 2, image.Height / 2);
      document.Save("DrawImage.pdf", true);
    }
  }
}
 

 

Visual Basic :

Imports System.Drawing

Module DrawImage
  Sub Main()
    Dim document As PDFDocument = New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
    Dim canvas As PDFCanvas = document.Pages(0).Canvas
    Dim image As PDFImage = New PDFImage("../../images/two_pilots.bmp")
    canvas.DrawImage(image, 20, 50)
    canvas.DrawImage(image, image.Width + 20, 50, image.Width / 2, image.Height / 2)
    document.Save("DrawImage.pdf", True)
  End Sub
End Module