Example #1
0
 private void startNewPage() {
   if (document.isOpen()) {
     document.newPage();
   } else {
     document.open();
   }
 }
 private static void concatPDFs(List<String> pdfs, OutputStream outputStream, String tempDiv) {
   ByteArrayOutputStream byteStream = null;
   Document document = new Document();
   try {
     PdfCopy copy = new PdfCopy(document, outputStream);
     document.open();
     for (String pdf : pdfs) {
       String fileLocation = tempDiv + pdf;
       InputStream templateIs = new FileInputStream(fileLocation);
       PdfReader reader = new PdfReader(templateIs);
       byteStream = new ByteArrayOutputStream();
       PdfStamper stamper = new PdfStamper(reader, byteStream);
       stamper.setFreeTextFlattening(true);
       stamper.setFormFlattening(true);
       stamper.close();
       PdfReader pdfReader = new PdfReader(byteStream.toByteArray());
       for (int page = 0; page < pdfReader.getNumberOfPages(); ) {
         copy.addPage(copy.getImportedPage(pdfReader, ++page));
       }
       pdfReader.close();
       reader.close();
     }
     document.close();
     copy.close();
   } catch (Exception e) {
     logger.error(e, e);
   } finally {
     if (document.isOpen()) document.close();
     try {
       if (outputStream != null) outputStream.close();
     } catch (IOException ioe) {
       logger.error(ioe, ioe);
     }
   }
 }
Example #3
0
  public static void agregarMatrizPDF() {
    PdfPTable table = new PdfPTable(matriz[0].length + 3);

    FileOutputStream archivo = null;
    try {
      archivo = new FileOutputStream("tmp.pdf");
    } catch (FileNotFoundException ex) {
      Logger.getLogger(principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    Document documento = new Document();
    try {
      PdfWriter.getInstance(documento, archivo);
    } catch (DocumentException ex) {
      Logger.getLogger(principal.class.getName()).log(Level.SEVERE, null, ex);
    }
    documento.open();
    try {
      documento.add(new Paragraph("Gran M\n"));
    } catch (DocumentException ex) {
      Logger.getLogger(principal.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (int i = 0; i < labelMatriz.length; i++) {
      table.addCell(labelMatriz[i].getText());
    }

    for (int i = 0; i < (matriz.length); i++) {
      for (int k = 0; k < (matriz[0].length + 3); k++) {
        if (k < 3) {
          table.addCell(rvz[i][k].toString());

        } else {
          table.addCell(matriz[i][k - 3].toString());
        }
      }
    }

    try {
      if (documento.isOpen()) {
        documento.add(table);
      }
    } catch (DocumentException ex) {
      Logger.getLogger(principal.class.getName()).log(Level.SEVERE, null, ex);
    }

    documento.close();
  }
 public void openDoc() {
   if (!nd.isOpen()) nd.open();
 }