in iText, Maven, Tutorials

[Tutorial] Create a PDF document with Maven and iText

Here is a quick way to start learning how to use the open-source library iText to generate PDF documents.
I start with the archetype maven-archetype-quickstart (number 101, which is the default archetype), an archetype which contains a sample Maven project.

mvn archetype:generate

You need to edit the POM.xml file to add the iText library dependency.

 <dependency>
            <groupId>com.lowagie</groupId>
            <artifactId>itext</artifactId>
            <version>2.0.7</version>
        </dependency>

Then a couple of Maven commands and you are done :

...
mvn clean install
...
mvn exec:java -Dexec.mainClass="com.company.celinio.iText.Main"
package com.company.celinio.iText;
 
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Chunk;
import com.lowagie.text.Font;


import java.awt.Color;
import java.io.FileOutputStream;
import java.util.Date;
 
public class Main {
    public static void main(String[] args) {
        try {
            Document document = new Document();
            PdfWriter pdfWriter = 
            PdfWriter.getInstance(document, new FileOutputStream("FourthTuto.pdf"));
            
            // Properties
            document.addAuthor("Celinio");
            document.addCreator("Celinio");
            document.addSubject("iText with Maven");
						document.addTitle("Fourth tutorial");
						document.addKeywords("iText, Maven, Java");
            
            document.open();
            
            Chunk chunk = new Chunk("Fourth tutorial");
						Font font = new Font(Font.COURIER);
						font.setStyle(Font.UNDERLINE);
						font.setStyle(Font.ITALIC);
						chunk.setFont(font);
						chunk.setBackground(Color.CYAN);
						document.add(chunk);

            document.add(new Paragraph("Testing with Maven."));
            document.add(new Paragraph("Another paragraph."));
            document.add(new Paragraph(new Date().toString()));  

            document.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

And here is the result :

Properties of the document :

Link to the video tutorial : http://www.celinio.net/tutorials/MavenTuto4.htm

Other links :
http://itextpdf.com/

Webmentions

  • The Latest Ukraine News

    The Latest Ukraine News

    The Latest Ukraine News

  • Ukraine news – live

    Ukraine news – live

    Ukraine news – live

  • Ukraine

    Ukraine

    Ukraine

  • War in Ukraine

    War in Ukraine

    War in Ukraine

  • bucha killings

    bucha killings

    bucha killings

  • cleantalkorg2.ru

    cleantalkorg2.ru

    cleantalkorg2.ru

  • bit.ly

    bit.ly

    bit.ly

  • chelovek soznaniye mozg

    chelovek soznaniye mozg

    chelovek soznaniye mozg

  • psy

    psy

    psy

  • tor-lyubov-i-grom.ru

    tor-lyubov-i-grom.ru

    tor-lyubov-i-grom.ru

  • Link

    Link

    Link

  • https://bit.ly/psikholog-muzhchina-onlayn

    https://bit.ly/psikholog-muzhchina-onlayn

    https://bit.ly/psikholog-muzhchina-onlayn

  • netstate.ru

    netstate.ru

    netstate.ru

  • Psikholog

    Psikholog

    Psikholog

  • hdorg2.ru

    hdorg2.ru

    hdorg2.ru

  • hd-tor-2022

    hd-tor-2022

    hd-tor-2022

  • film-tor-2022

    film-tor-2022

    film-tor-2022

  • tor-lyubov-i-grom

    tor-lyubov-i-grom

    tor-lyubov-i-grom

  • 01211

    01211

    01211 21546

  • 3NOZC44

    3NOZC44

    3NOZC44

  • 3Hk12Bl

    3Hk12Bl

    3Hk12Bl

  • chelovek-iz-90-h

    chelovek-iz-90-h

    chelovek-iz-90-h

  • russianmanagement.com

    russianmanagement.com

    russianmanagement.com

  • Øêàëà òîíîâ

    Øêàëà òîíîâ

    Øêàëà òîíîâ

  • SHKALA TONOV

    SHKALA TONOV

    SHKALA TONOV

  • https://ria.ru/20100906/272903623.html

    https://ria.ru/20100906/272903623.html

    https://ria.ru/20100906/272903623.html

  • D6tuzANh

    D6tuzANh

    D6tuzANh

  • qQ8KZZE6

    qQ8KZZE6

    qQ8KZZE6

  • DPTPtNqS

    DPTPtNqS

    DPTPtNqS

  • uels ukrain

    uels ukrain

    uels ukrain

  • psy online

    psy online

    psy online

  • moskva psiholog online

    moskva psiholog online

    moskva psiholog online

  • projectio

    projectio

    projectio

  • Intimsiti-v-obhod-blokirovok

    Intimsiti-v-obhod-blokirovok

    Intimsiti-v-obhod-blokirovok

  • irida-design.ru

    irida-design.ru

    irida-design.ru

  • vkl-design.ru

    vkl-design.ru

    vkl-design.ru

  • designmsu.ru

    designmsu.ru

    designmsu.ru

  • design-human.ru

    design-human.ru

    design-human.ru

  • YA-krasneyu

    YA-krasneyu

    YA-krasneyu

  • designchita.ru

    designchita.ru

    designchita.ru

  • FILM

    FILM

    FILM

  • Krylya-nad-Berlinom

    Krylya-nad-Berlinom

    Krylya-nad-Berlinom

  • Zvezdy-v-Afrike-2-sezon-14-seriya

    Zvezdy-v-Afrike-2-sezon-14-seriya

    Zvezdy-v-Afrike-2-sezon-14-seriya

  • Netflix

    Netflix

    Netflix

  • ivanesva

    ivanesva

    ivanesva

  • XVIDEOSCOM Videos

    XVIDEOSCOM Videos

    XVIDEOSCOM Videos

  • Xvideos

    Xvideos

    Xvideos

  • TopGun2022

    TopGun2022

    TopGun2022

  • kinoteatrzarya.ru

    kinoteatrzarya.ru

    kinoteatrzarya.ru

  • 9-05-2022

    9-05-2022

    9-05-2022

  • gRh9UPV

    gRh9UPV

    gRh9UPV

  • filmfilmfilmes

    filmfilmfilmes

    filmfilmfilmes

  • smotretonlaynfilmyiserialy.ru

    smotretonlaynfilmyiserialy.ru

    smotretonlaynfilmyiserialy.ru

  • yutub

    yutub

    yutub

  • z.globus-kino.ru

    z.globus-kino.ru

    z.globus-kino.ru

  • Russia launches Ukraine

    Russia launches Ukraine

    Russia launches Ukraine

  • my-vse-mertvy-2022

    my-vse-mertvy-2022

    my-vse-mertvy-2022

  • 3L1poB8

    3L1poB8

    3L1poB8

  • 3rrZhf7

    3rrZhf7

    3rrZhf7

  • 3GrvxDp

    3GrvxDp

    3GrvxDp

  • 3J6w3bD

    3J6w3bD

    3J6w3bD

  • 34tfA26

    34tfA26

    34tfA26

  • uliocx

    uliocx

    uliocx

  • 3rpUI4X

    3rpUI4X

    3rpUI4X

  • Dead-Inside

    Dead-Inside

    Dead-Inside

  • arrogant

    arrogant

    arrogant

  • ne-smotrite-naverx

    ne-smotrite-naverx

    ne-smotrite-naverx

  • swimming pool pump

    swimming pool pump

    Automatic Pool Cover Pump

  • aabbx.store

    aabbx.store

    aabbx.store