PDF jet

Using the Image class


Example_03.pdf
using System;
using System.IO;

using PDFjet.NET;


/**
 *  Example_03.cs
 *
 */
public class Example_03 {

    public Example_03() {

        FileStream fos = new FileStream("Example_03.pdf", FileMode.Create);
        BufferedStream bos = new BufferedStream(fos);

        PDF pdf = new PDF(bos);

        Font f1 = new Font(pdf, CoreFont.HELVETICA);

        String fileName = "images/eu-map.png";
        FileStream fis1 = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        Image image1 = new Image(pdf, fis1, ImageType.PNG);

        fileName = "images/fruit.jpg"; 
        FileStream fis2 = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        Image image2 = new Image(pdf, fis2, ImageType.JPG);

        fileName = "images/mt-map.bmp"; 
        FileStream fis3 = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        Image image3 = new Image(pdf, fis3, ImageType.BMP);

        Page page = new Page(pdf, A4.PORTRAIT);

        TextLine text = new TextLine(f1,
                "The map below is an embedded PNG image");
        text.SetPosition(90.0f, 30.0f);
        text.DrawOn(page);

        image1.SetPosition(90.0f, 40.0f);
        image1.DrawOn(page);

        text.SetText(
                "JPG image file embedded once and drawn 3 times");
        text.SetPosition(90.0f, 550.0f);
        text.DrawOn(page);

        image2.SetPosition(90.0f, 560.0f);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        image2.SetPosition(260.0f, 560.0f);
        image2.SetRotateCW90(true);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        image2.SetPosition(350.0f, 560.0f);
        image2.SetRotateCW90(false);
        image2.ScaleBy(0.5f);
        image2.DrawOn(page);

        text.SetText(
                "The map on the right is an embedded BMP image");
        text.SetUnderline(true);
        text.SetStrikeLine(true);
        text.SetTextDirection(15);
        text.SetPosition(90.0f, 800.0f);
        text.DrawOn(page);

        image3.SetPosition(390.0f, 630.0f);
        image3.ScaleBy(0.5f);
        image3.DrawOn(page);

        Page page2 = new Page(pdf, A4.PORTRAIT);
        image1.DrawOn(page2);

        pdf.Flush();
        bos.Close();
    }

    public static void Main(String[] args) {
        try {
            new Example_03();
        }
        catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }

}   // End of Example_03.cs

© 2017 Innovatics Inc.