private void addMetaData(Document document) {
   document.addTitle("My first PDF");
   document.addSubject("Using iText");
   document.addKeywords("Java, PDF, iText");
   document.addAuthor("Lars Vogel");
   document.addCreator("Lars Vogel");
 }
 private void addMetaData(Document document) {
   String title = mContext.getString(R.string.brew_shop_recipe_colon) + " " + mRecipe.getName();
   String author = mContext.getString(R.string.brew_shop);
   document.addTitle(title);
   document.addSubject(title);
   document.addAuthor(author);
   document.addCreator(author);
 }
  private Document buildMetadata(Document document, String date) {
    String author =
        authHelper.getCurrentUser().getAgent().getNom()
            + " "
            + authHelper.getCurrentUser().getAgent().getPrenom();
    document.addAuthor(author);
    document.addCreationDate();
    document.addCreator(author);
    document.addTitle("FICHE EVENEMENTIELLE " + date);
    document.addSubject("FICHE EVENEMENTIELLE " + date);

    return document;
  }
  private Document buildMetadata(Document document, Fiche fiche) {
    Agent a = fiche.getHistoriques().iterator().next().getUtilisateur().getAgent();
    document.addAuthor(a.getNom() + " " + a.getPrenom());
    document.addCreationDate();
    document.addCreator(
        authHelper.getCurrentUser().getAgent().getNom()
            + " "
            + authHelper.getCurrentUser().getAgent().getPrenom());
    document.addTitle("MAIN COURANTE " + fiche.getReference());
    document.addSubject("MAIN COURANTE " + fiche.getReference());

    StringBuilder keywords = new StringBuilder();
    keywords.append(fiche.getReference());
    keywords.append(",");
    keywords.append(fiche.getAdresse().getNomVoie().getLibelle());
    keywords.append(",");
    for (Fait f : fiche.getFaits()) {
      keywords.append(f.getNature().getLibelleCourt());
      keywords.append(",");
    }
    document.addKeywords(keywords.toString());

    return document;
  }
示例#5
0
  public void GetLzTianya(String destUrl, String filename) throws IOException {
    InputStreamReader isr = null;
    if (isavepage) {
      saveToFile(destUrl, filename);
      FileInputStream Openfile = new FileInputStream(tmp_path + File.separatorChar + filename);
      isr = new InputStreamReader(Openfile, "UTF-8");
    } else {
      BufferedInputStream bis = null;
      HttpURLConnection httpUrl = null;
      URL url = null;
      // 建立链接
      url = new URL(destUrl);
      httpUrl = (HttpURLConnection) url.openConnection();
      // 连接指定的资源
      httpUrl.connect();
      // 获取网络输入流
      bis = new BufferedInputStream(httpUrl.getInputStream());
      isr = new InputStreamReader(bis, "UTF-8");
    }

    BufferedReader in = new BufferedReader(isr);
    String temp = in.readLine();
    String c_line = System.getProperty("line.separator");
    if (title_mark == 1 && !downpdf) {
      String filePath = cu_path + File.separatorChar + title + ".txt";
      filePath = filePath.toString();
      File myFilePath = new File(filePath);
      writer = new FileWriter(myFilePath, true);
    }
    while (!temp.equals("</html>")) {
      if (temp.indexOf("<title>") != -1 && title_mark == 0) {
        if (!downpdf) {
          String filePath = cu_path + File.separatorChar + title + ".txt";
          filePath = filePath.toString();
          File myFilePath = new File(filePath);
          if (myFilePath.exists() && ioverwrite) {
            myFilePath.delete();
          }
          writer = new FileWriter(myFilePath, true);
          writer.write(title + c_line);
        }
        title_mark = 1;
      } else if (temp.indexOf("<div class=\"atl-info\">") != -1 && mark != 1) {
        temp = in.readLine();
        String[] a = temp.split(">");
        String[] aa = temp.split("\"");
        String[] b = a[2].split("<");
        author = b[0];
        link = aa[1];
        if (downpdf) {
          String filePath = cu_path + File.separatorChar + title + ".pdf";
          filePath = filePath.toString();
          try {
            PdfWriter.getInstance(doc, new FileOutputStream(filePath));
            Paragraph pf = new Paragraph(title, fontChinese);
            Paragraph cline = new Paragraph(" ");
            doc.addTitle(title);
            doc.addAuthor(author);
            doc.addCreator(soft_name);
            doc.open();
            doc.add(pf);
            doc.add(cline);
            pf = new Paragraph("原帖地址: " + page, fontChinese);
            doc.add(pf);
            doc.add(cline);
            pf = new Paragraph("作者:" + author, fontChinese);
            doc.add(pf);
            doc.add(cline);
            doc.add(cline);
          } catch (DocumentException e) {
            System.out.println(e);
          }
        } else {
          writer.write(c_line + "原帖地址: " + page + c_line);
          writer.write(c_line + "作者: " + author + c_line + c_line);
        }
        while (temp.indexOf("<div class=\"bbs-content clearfix\">") == -1) {
          temp = in.readLine();
        }
        while (temp.indexOf("</div>") == -1) {
          temp = temp + in.readLine();
        }
        String[] story1 = temp.split("<div class=\"bbs-content clearfix\">");
        String[] story2 = story1[1].split("</div>");
        String[] story = story2[0].split("<br>");
        for (int i = 0; i < story.length; i++) {
          if (story[i].indexOf("<center>") != -1 && story[i].indexOf("</center>") != -1) continue;
          else if (story[i].indexOf("<img src=\"") != -1) {
            String[] img = story[i].split("\"");
            Write("(" + img[1] + ")");
            Write(c_line);
          } else if (story[i].indexOf("type=\"application/x-shockwave-flash\"") != -1) {
            String[] tmp1 = story[i].split("src=\"");
            String[] flash = tmp1[1].split("\"");
            Write("[Flash 地址:" + flash[0] + "]");
          } else {
            Write(story[i]);
            Write(c_line);
          }
        }
        mark = 1;
        if (betweenline) {
          Write(c_line);
          Write(line_mark);
          Write(c_line);
        } else {
          Write(c_line);
        }
      } else if (mark == 1) {
        if (temp.indexOf("<div class=\"host-ico\">楼主</div>") != -1) {
          while (temp.indexOf("<div class=\"bbs-content\">") == -1) {
            temp = in.readLine();
          }
          while (temp.indexOf("</div>") == -1) {
            temp = temp + in.readLine();
          }
          String[] story1 = temp.split("<div class=\"bbs-content\">");
          String[] story2 = story1[1].split("</div>");
          String[] story = story2[0].split("<br>");
          for (int i = 0; i < story.length; i++) {
            if (story[i].indexOf("<center>") != -1 && story[i].indexOf("</center>") != -1) continue;
            else if (story[i].indexOf("<img src=\"") != -1) {
              String[] img = story[i].split("\"");
              Write("(" + img[1] + ")");
              Write(c_line);
            } else if (story[i].indexOf("type=\"application/x-shockwave-flash\"") != -1) {
              String[] tmp1 = story[i].split("src=\"");
              String[] flash = tmp1[1].split("\"");
              Write("[Flash 地址:" + flash[0] + "]");
            } else {
              Write(story[i]);
              Write(c_line);
            }
          }
          if (betweenline) {
            Write(c_line);
            Write(line_mark);
            Write(c_line);
          } else {
            Write(c_line);
          }
        }
      }

      if (pages == 1 && temp.indexOf("<div class=\"atl-pages\">") != -1) {
        String tmp1 = in.readLine();
        String tmp2 = in.readLine();
        while (tmp2.indexOf("class=\"js-keyboard-next\"") == -1) {
          tmp1 = tmp2;
          tmp2 = in.readLine();
        }
        String[] tmp_a = tmp1.split(">");
        String[] tmp_b = tmp_a[1].split("<");

        pages = Integer.parseInt(tmp_b[0]);
      }
      temp = in.readLine();
    }
    if (!downpdf) writer.close();
    in.close();
  }
示例#6
0
  public void drukuj() throws FileNotFoundException, DocumentException, IOException {
    Document document = new Document();
    PdfWriter.getInstance(
            document,
            new FileOutputStream(
                "C:/Users/Osito/Documents/NetBeansProjects/npkpir_23/build/web/wydruki/vatsuma"
                    + wpisView.getPodatnikWpisu()
                    + ".pdf"))
        .setInitialLeading(16);
    document.addTitle("Zestawienie sum z ewidencji VAT");
    document.addAuthor("Biuro Rachunkowe Taxman Grzegorz Grzelczyk");
    document.addSubject("Wydruk danych z ewidencji VAT");
    document.addKeywords("VAT, PDF");
    document.addCreator("Grzegorz Grzelczyk");
    document.open();
    // Rectangle rect = new Rectangle(0, 832, 136, 800);
    // rect.setBackgroundColor(BaseColor.RED);
    // document.add(rect);
    document.add(new Chunk("Biuro Rachunkowe Taxman"));
    document.add(Chunk.NEWLINE);
    BaseFont helvetica =
        BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    Font font = new Font(helvetica, 12);
    Font fontM = new Font(helvetica, 10);
    Font fontS = new Font(helvetica, 6);
    document.add(Chunk.NEWLINE);
    Date date = Calendar.getInstance().getTime();
    DateFormat formatt = new SimpleDateFormat("dd/MM/yyyy");
    String today = formatt.format(date);
    System.out.println("PdfVATsuma Today : " + today);
    Paragraph miziu =
        new Paragraph(
            new Phrase(
                "Szczecin, dnia "
                    + Data.datapk(wpisView.getRokWpisuSt(), wpisView.getMiesiacWpisu()),
                font));
    miziu.setAlignment(Element.ALIGN_RIGHT);
    miziu.setLeading(50);
    document.add(miziu);
    document.add(new Chunk().NEWLINE);
    Paragraph miziu1 = new Paragraph(new Phrase("Zestawienie ewidencji VAT ", font));
    miziu1.setAlignment(Element.ALIGN_CENTER);
    document.add(miziu1);
    document.add(new Chunk().NEWLINE);
    miziu1 =
        new Paragraph(
            new Phrase(
                "okres rozliczeniony " + wpisView.getMiesiacWpisu() + "/" + wpisView.getRokWpisu(),
                fontM));
    document.add(miziu1);
    document.add(new Chunk().NEWLINE);
    miziu1 = new Paragraph(new Phrase("Firma: " + wpisView.getPodatnikWpisu(), fontM));
    document.add(miziu1);
    Podatnik pod = podatnikDAO.find(wpisView.getPodatnikWpisu());
    miziu1 =
        new Paragraph(
            new Phrase(
                "adres: " + pod.getMiejscowosc() + " " + pod.getUlica() + " " + pod.getNrdomu(),
                fontM));
    document.add(miziu1);
    miziu1 = new Paragraph(new Phrase("NIP: " + pod.getNip(), fontM));
    document.add(miziu1);
    PdfPTable tableSprzedaz = new PdfPTable(5);
    tableSprzedaz.setWidths(new int[] {1, 5, 2, 2, 2});
    PdfPTable tableZakup = new PdfPTable(5);
    tableZakup.setWidths(new int[] {1, 5, 2, 2, 2});
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(2);
    formatter.setGroupingUsed(true);
    List<EVatwpisSuma> sumaVatSprzedaz = new ArrayList<>();
    List<EVatwpisSuma> sumaVatZakup = new ArrayList<>();
    Ewidencjevat lista;
    try {
      lista =
          ewidencjeVatDAO.find(
              wpisView.getRokWpisu().toString(),
              wpisView.getMiesiacWpisu(),
              wpisView.getPodatnikWpisu());
    } catch (Exception e) {
      Integer kwartal =
          Integer.parseInt(
              Kwartaly.getMapanrkw().get(Integer.parseInt(wpisView.getMiesiacWpisu())));
      List<String> miesiacewkwartale = Kwartaly.getMapakwnr().get(kwartal);
      lista =
          ewidencjeVatDAO.find(
              wpisView.getRokWpisu().toString(),
              miesiacewkwartale.get(2),
              wpisView.getPodatnikWpisu());
    }
    for (EVatwpisSuma ew : lista.getSumaewidencji().values()) {
      String typeewidencji = ew.getEwidencja().getTypewidencji();
      switch (typeewidencji) {
        case "s":
          sumaVatSprzedaz.add(ew);
          break;
        case "z":
          sumaVatZakup.add(ew);
          break;
        case "sz":
          sumaVatSprzedaz.add(ew);
          sumaVatZakup.add(ew);
          break;
      }
    }
    // tu robimy wykaz ewidencji sprzedazy
    document.add(Chunk.NEWLINE);
    miziu1 = new Paragraph(new Phrase("zestawienie ewidencji sprzedaży", fontM));
    document.add(miziu1);
    try {
      tableSprzedaz.addCell(ustawfrazebez("lp", "center", 10));
      tableSprzedaz.addCell(ustawfrazebez("ewidencja", "center", 10));
      tableSprzedaz.addCell(ustawfrazebez("netto", "center", 10));
      tableSprzedaz.addCell(ustawfrazebez("vat", "center", 10));
      tableSprzedaz.addCell(ustawfrazebez("brutto", "center", 10));
      tableSprzedaz.setHeaderRows(1);
      int i = 1;
      for (EVatwpisSuma p : sumaVatSprzedaz) {
        tableSprzedaz.addCell(ustawfrazebez(String.valueOf(i), "center", 10));
        tableSprzedaz.addCell(ustawfrazebez(p.getEwidencja().getNazwa(), "left", 10));
        tableSprzedaz.addCell(
            ustawfrazebez(String.valueOf(formatter.format(p.getNetto())), "right", 10));
        tableSprzedaz.addCell(
            ustawfrazebez(String.valueOf(formatter.format(p.getVat())), "right", 10));
        try {
          tableSprzedaz.addCell(
              ustawfrazebez(
                  String.valueOf(formatter.format(p.getVat().add(p.getNetto()))), "right", 10));
        } catch (Exception e) {
          tableSprzedaz.addCell(ustawfrazebez("", "right", 10));
        }
        i++;
      }
    } catch (DocumentException | IOException e) {

    }
    document.add(Chunk.NEWLINE);
    document.add(tableSprzedaz);
    document.add(Chunk.NEWLINE);
    // tu robimy wykaz ewidencji zakupu
    miziu1 = new Paragraph(new Phrase("zestawienie ewidencji zakupu", fontM));
    document.add(miziu1);
    try {
      tableZakup.addCell(ustawfrazebez("lp", "center", 10));
      tableZakup.addCell(ustawfrazebez("ewidencja", "center", 10));
      tableZakup.addCell(ustawfrazebez("netto", "center", 10));
      tableZakup.addCell(ustawfrazebez("vat", "center", 10));
      tableZakup.addCell(ustawfrazebez("brutto", "center", 10));
      tableZakup.setHeaderRows(1);
      int i = 1;
      for (EVatwpisSuma p : sumaVatZakup) {
        tableZakup.addCell(ustawfrazebez(String.valueOf(i), "center", 10));
        tableZakup.addCell(ustawfrazebez(p.getEwidencja().getNazwa(), "left", 10));
        tableZakup.addCell(
            ustawfrazebez(String.valueOf(formatter.format(p.getNetto())), "right", 10));
        tableZakup.addCell(
            ustawfrazebez(String.valueOf(formatter.format(p.getVat())), "right", 10));
        try {
          tableZakup.addCell(
              ustawfrazebez(
                  String.valueOf(formatter.format(p.getVat().add(p.getNetto()))), "right", 10));
        } catch (Exception e) {
          tableZakup.addCell(ustawfrazebez("", "right", 10));
        }
        i++;
      }
    } catch (DocumentException | IOException e) {

    }
    document.add(Chunk.NEWLINE);
    document.add(tableZakup);
    document.add(Chunk.NEWLINE);
    Uz uz = wpisView.getWprowadzil();
    document.add(new Paragraph(String.valueOf(uz.getImie() + " " + uz.getNazw()), fontM));
    document.add(new Paragraph("___________________________", fontM));
    document.add(new Paragraph("sporządził", fontM));
    document.close();
    // Msg.msg("i", "Wydrukowano sume ewidencji VAT", "form:messages");
  }
  private static PdfReader createPdf(
      String globalTitle, Date creationDate, ScrambleRequest scrambleRequest)
      throws DocumentException, IOException {
    azzert(scrambleRequest.scrambles.length > 0);
    ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
    Rectangle pageSize = PageSize.LETTER;
    Document doc = new Document(pageSize, 0, 0, 75, 75);
    PdfWriter docWriter = PdfWriter.getInstance(doc, pdfOut);

    docWriter.setBoxSize(
        "art", new Rectangle(36, 54, pageSize.getWidth() - 36, pageSize.getHeight() - 54));

    doc.addCreationDate();
    doc.addProducer();
    if (globalTitle != null) {
      doc.addTitle(globalTitle);
    }

    doc.open();
    // Note that we ignore scrambleRequest.copies here.
    addScrambles(docWriter, doc, scrambleRequest, globalTitle);
    doc.close();

    // TODO - is there a better way to convert from a PdfWriter to a PdfReader?
    PdfReader pr = new PdfReader(pdfOut.toByteArray());
    if (scrambleRequest.fmc) {
      // We don't watermark the FMC sheets because they already have
      // the competition name on them.
      return pr;
    }

    pdfOut = new ByteArrayOutputStream();
    doc = new Document(pageSize, 0, 0, 75, 75);
    docWriter = PdfWriter.getInstance(doc, pdfOut);
    doc.open();

    PdfContentByte cb = docWriter.getDirectContent();

    for (int pageN = 1; pageN <= pr.getNumberOfPages(); pageN++) {
      PdfImportedPage page = docWriter.getImportedPage(pr, pageN);

      doc.newPage();
      cb.addTemplate(page, 0, 0);

      Rectangle rect = pr.getBoxSize(pageN, "art");

      // Header
      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_LEFT,
          new Phrase(Utils.SDF.format(creationDate)),
          rect.getLeft(),
          rect.getTop(),
          0);

      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(globalTitle),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getTop() - 60,
          0);

      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(scrambleRequest.title),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getTop() - 45,
          0);

      if (pr.getNumberOfPages() > 1) {
        ColumnText.showTextAligned(
            cb,
            Element.ALIGN_RIGHT,
            new Phrase(pageN + "/" + pr.getNumberOfPages()),
            rect.getRight(),
            rect.getTop(),
            0);
      }

      // Footer
      String generatedBy = "Generated by " + Utils.getProjectName() + "-" + Utils.getVersion();
      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(generatedBy),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getBottom() + 40,
          0);
    }

    doc.close();

    // TODO - is there a better way to convert from a PdfWriter to a PdfReader?
    pr = new PdfReader(pdfOut.toByteArray());
    return pr;

    //      The PdfStamper class doesn't seem to be working.
    //      pdfOut = new ByteArrayOutputStream();
    //      PdfStamper ps = new PdfStamper(pr, pdfOut);
    //
    //      for(int pageN = 1; pageN <= pr.getNumberOfPages(); pageN++) {
    //          PdfContentByte pb = ps.getUnderContent(pageN);
    //          Rectangle rect = pr.getBoxSize(pageN, "art");
    //          System.out.println(rect.getLeft());
    //          System.out.println(rect.getWidth());
    //          ColumnText.showTextAligned(pb,
    //                  Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0);
    ////            ColumnText.showTextAligned(pb,
    ////                    Element.ALIGN_CENTER, new Phrase("HELLO WORLD"),
    ////                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop(), 0);
    //      }
    //      ps.close();
    //      return ps.getReader();
  }
示例#8
0
 // iText allows to add metadata to the PDF which can be viewed in your Adobe
 // Reader
 // under File -> Properties
 public void addMetaData(Document document, CustomerOrder customerOrder) {
   document.addTitle("GFC PhotoBooth Invoice");
   //  document.addKeywords("GFC, PDF, iText");
 }