iText creates the PDF, opens it, but does not print anything

0

I am currently learning iText, since my work demands it from me. I assume that my knowledge in Java is not null, but neither are they advanced.

So, I decided to take the equatorial one from the iText website and start applying the tutorials that it has. And my first mistake I find in chapter 1 (I put the NetBeans code). The fact is that I copy and paste the text as is and NetBeans starts to give me errors. Among them I have to add a function ( try , catch ) to write the code.

I put it "automatically" and the result is a generated PDF, but it does not paint me a paragraph or anything.

If you can help me, I would be grateful.

    /*
 * This example is part of the iText 7 tutorial.
 */
package tutorial.chapter01.eva;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.test.annotations.WrapToTest;
import com.itextpdf.text.DocumentException;

import java.io.File;
import java.io.IOException;

/**
 * Simple Hello World example.
 */
@WrapToTest
public class C01E01_HelloWorld {

    public static final String DEST = "results/chapter01/hello_world25.pdf";

    public static void main(String args[]) throws IOException {
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new C01E01_HelloWorld().createPdf(DEST);
    }

    public void createPdf(String dest) throws IOException {
        //Initialize PDF writer
        PdfWriter writer = new PdfWriter(dest);

        //Initialize PDF document
        PdfDocument pdf = new PdfDocument(writer);

        try ( // Initialize document
            Document document = new Document(pdf)) {
            //Add paragraph to the document
            document.add(new Paragraph("Hello World!"));
            //Close document
        }
        document.close();
    }
}
    
asked by Eva MV 25.05.2018 в 12:30
source

0 answers