📜  cpp 实时代码 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:39.398000             🧑  作者: Mango

代码示例1
package devmedia;

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

public class GeneratorPDF {

    public static void main(String[] args) {
           // criação do documento
          Document document = new Document();
          try {

              PdfWriter.getInstance(document, new FileOutputStream("C:\\PDF_DevMedia.pdf"));
              document.open();

              // adicionando um parágrafo no documento
              document.add(new Paragraph("Gerando PDF - Java"));
    }
          catch(DocumentException de) {
              System.err.println(de.getMessage());
          }
          catch(IOException ioe) {
              System.err.println(ioe.getMessage());
          }
          document.close();
      }
    }