Tutorial sobre como gerar um PDF

3 respostas
D

Salve Galera…
Estava tentando executar um tutorial aqui do PJ sobre como gerar um PDF.
e ele está dando o seguinte erro:

java.lang.Error: Unresolved compilation problems:
Document cannot be resolved or is not a type
Document cannot be resolved or is not a type
PdfWriter cannot be resolved
Paragraph cannot be resolved or is not a type
DocumentException cannot be resolved or is not a type

at Chap0101.main(Chap0101.java:24)</blockquote>

o código é:

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class Chap0101 &#123;

    public static void main&#40;String&#91;&#93; args&#41; &#123;

        System.out.println&#40;"Chapter 1 example 1&#58; Hello World"&#41;;

        // step 1&#58; creation of a document-object
        Document document = new Document&#40;&#41;;

        try &#123;

            // step 2&#58;
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file

            PdfWriter.getInstance&#40;document, new
FileOutputStream&#40;"Chap0101.pdf"&#41;&#41;;

            // step 3&#58; we open the document
            document.open&#40;&#41;;

            // step 4&#58; we add a paragraph to the document
            document.add&#40;new Paragraph&#40;"Hello World"&#41;&#41;;

        &#125;
        catch&#40;DocumentException de&#41; &#123;
            System.err.println&#40;de.getMessage&#40;&#41;&#41;;
        &#125;
        catch&#40;IOException ioe&#41; &#123;
            System.err.println&#40;ioe.getMessage&#40;&#41;&#41;;
        &#125;

        // step 5&#58; we close the document
        document.close&#40;&#41;;
    &#125;
&#125;

No mais é só!

3 Respostas

A

kra,
pelo q parece está faltando fazer o import destas classes:

Document
Paragraph
DocumentException

[]'s

A

tente colocar estes imoportes…

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document; 
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
D

“AngeloCuiaba”:
tente colocar estes imoportes…

import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter;

Cara continuo com os mesmos erros, será que eu não preciso adicionar o pacote com.lowaggie na aplicação não o JAR?
Poxa se for, podiam ter falado o link para eu baixar isso no tutorial, ajudaria.

Criado 26 de agosto de 2004
Ultima resposta 27 de ago. de 2004
Respostas 3
Participantes 3