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");
 }
Ejemplo n.º 2
0
  public static void exportImg() {
    Document document = null;
    try {
      //            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
      // BaseFont.NOT_EMBEDDED);// 设置中文字体
      //            Font headFont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小

      document = new Document();
      PdfWriter.getInstance(document, new FileOutputStream("D:/test/img.pdf"));
      // 设定文档的作者
      document.addAuthor("林计钦"); // 测试无效
      document.open();
      document.add(new Paragraph("你好,Img!"));
      // 读取一个图片
      Image image = Image.getInstance("D:/test/1.jpg");
      // 插入一个图片
      document.add(image);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      if (document != null) {
        document.close();
      }
    }
  }
Ejemplo n.º 3
0
 /**
  * Method to export charts as PDF files using the defined path.
  *
  * @param path The filename and absolute path.
  * @param chart The JFreeChart object.
  * @param width The width of the PDF file.
  * @param height The height of the PDF file.
  * @param mapper The font mapper for the PDF file.
  * @param title The title of the PDF file.
  * @throws IOException If writing a PDF file fails.
  */
 @SuppressWarnings("deprecation")
 public static void exportPdf(
     String path, JFreeChart chart, int width, int height, FontMapper mapper, String title)
     throws IOException {
   File file = new File(path);
   FileOutputStream pdfStream = new FileOutputStream(file);
   BufferedOutputStream pdfOutput = new BufferedOutputStream(pdfStream);
   Rectangle pagesize = new Rectangle(width, height);
   Document document = new Document();
   document.setPageSize(pagesize);
   document.setMargins(50, 50, 50, 50);
   document.addAuthor("OMSimulationTool");
   document.addSubject(title);
   try {
     PdfWriter pdfWriter = PdfWriter.getInstance(document, pdfOutput);
     document.open();
     PdfContentByte contentByte = pdfWriter.getDirectContent();
     PdfTemplate template = contentByte.createTemplate(width, height);
     Graphics2D g2D = template.createGraphics(width, height, mapper);
     Double r2D = new Rectangle2D.Double(0, 0, width, height);
     chart.draw(g2D, r2D);
     g2D.dispose();
     contentByte.addTemplate(template, 0, 0);
   } catch (DocumentException de) {
     JOptionPane.showMessageDialog(
         null,
         "Failed to write PDF document.\n" + de.getMessage(),
         "Failed",
         JOptionPane.ERROR_MESSAGE);
     de.printStackTrace();
   }
   document.close();
 }
Ejemplo n.º 4
0
 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;
  }
Ejemplo n.º 6
0
  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;
  }
Ejemplo n.º 7
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();
  }
Ejemplo n.º 8
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");
  }