LayerImageOnTextPDF.java Source code

Java tutorial

Introduction

Here is the source code for LayerImageOnTextPDF.java

Source

import java.io.FileOutputStream;

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

public class LayerImageOnTextPDF {
    public static void main(String[] args) {
        Document document = new Document();
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("LayerImageOnTextPDF.pdf"));
            document.open();

            Paragraph p = new Paragraph();
            for (int i = 0; i < 100; i++)
                p.add(new Chunk("Text Text Text Text Text Text Text Text "));
            document.add(p);

            Image img = Image.getInstance("logo.png");
            img.setAbsolutePosition(100, 500);
            document.add(img);

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        document.close();
    }

}