MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
    public static void main(String[] args) throws Exception {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
        document.open();
        Image tiff = Image.getInstance("dog.tiff");
        document.add(tiff);
        tiff.scalePercent(72f / tiff.getDpiX() * 100);
        document.add(new Paragraph("Show the image with 360 Dpi (scaled " + (7200f / tiff.getDpiX()) + "%):"));

        document.add(
                new Paragraph("Scaled width: " + tiff.scaledWidth() + "; scaled height: " + tiff.scaledHeight()));
        document.add(tiff);
        document.close();
    }
}