0

这个问题已经让我窒息了很长一段时间,现在正好一个多月。我尝试开发一个小型 Javafx 应用程序,我使用 ITEXT 5.3 版本,一切正常,我使用 icepdf 在 netbean 中显示生成的 PDF。完美地工作在netbeans中很好。但是一旦我尝试在netbean之外运行可执行jar程序,它就不会生成PDF。我尝试使用高级安装程序打包它并且pdf也没有生成。我尝试了一些解决方案,这个pdf不是由itext库生成的java应用程序,但它没有帮助。每一个帮助都将不胜感激这是我生成 PDF 的源代码:

     @FXML
    private void generatereportforresistance(ActionEvent event) throws IOException {
         XYSeries powerSeries = new XYSeries("Power_Speed relation");

        for (double i=0;i<getValue(13);i=i+0.01){
            double p=getPower(i)*0.51444;


        powerSeries.add(i, p);


        }
        XYDataset xyDataset = new XYSeriesCollection(powerSeries);
        JFreeChart chart = ChartFactory.createXYLineChart(
        "Effective Power V.S Speed", "Speed[knots]", "Power[KW]", xyDataset,
        PlotOrientation.VERTICAL, true, true, true);
     //Render the frame
    ChartFrame chartFrame = new ChartFrame("Power V.S speed Charts", chart);
    chartFrame.setIconImage(Toolkit.getDefaultToolkit().getImage("app_icon.png"));
    //chartFrame.setVisible(true);
    //chartFrame.setSize(800, 800);
    StandardChartTheme st = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme();
    st.setTitlePaint(Color.decode("#4572a7"));

    st.setRangeGridlinePaint( Color.decode("#C0C0C0"));
    st.setPlotBackgroundPaint( Color.white );
    st.setChartBackgroundPaint( Color.white );
    st.setGridBandPaint( Color.red );
    st.setAxisLabelPaint( Color.decode("#666666")  );
    st.apply( chart );

   double a_aa = r_a(getValue(14),getValue(13),getValue(17),getValue(2),getValue(18),getValue(0),getValue(3),getValue(8),getValue(7),getValue(9),getValue(10));

      double b_bb=r_tr(getValue(13),getValue(14),getValue(11),getValue(2),getValue(10));
      double c_cc=r_b(getValue(13),getValue(14),getValue(7),getValue(3),getValue(10),getValue(2),getValue(8),getValue(16));
      double d_dd=r_w(getValue(13),getValue(14),getValue(7),getValue(5),getValue(11),getValue(3),getValue(18),getValue(10),getValue(6),getValue(17),getValue(0),getValue(9),getValue(2),getValue(8),getValue(16));
      double e_ee=r_app(getValue(14),getValue(13),getValue(0),getValue(15),getValue(12));
      double f_ff=r_f(getValue(14),getValue(13),getValue(0),getValue(15),getValue(2),getValue(10),getValue(17),getValue(7),getValue(18),getValue(9),getValue(6));
      double totoal =f_ff+a_aa+b_bb+c_cc+d_dd+e_ee;
      double p_e =totoal *getValue(13)*0.51444;
      double p_s =p_e/getValue(19);
       //double values of parameters para = new 
       double[] val = new double[9];
       val[0]=a_aa; val[1]=b_bb; val[2]=c_cc; val[3]=d_dd; val[4]=e_ee; val[5]=f_ff; val[6]=totoal; val[7]=p_e; val[8]=p_s;

        //string values of units and parameters namings
        String [] para = new String[9];
        para[0]="Model_Ship Correlation Resistance";para[1]="Additional Pressure Resisitance of immersed Transom";para[2]="Additional pressure resistance of bulbous bow near water surface";
        para[3]="Wave Resistance";para[4]="Resistance due to Appendages";para[5]="Frictional resistance";para[6]="Total resistance";
        para[7]="Effective Power";para[8]="Shaft Power";
        String [] units = new String[9];
        units[0]="KN"; units[1]="KN"; units[1]="KN"; units[2]="KN"; units[3]="KN"; units[4]="KN"; units[5]="KN"; units[6]="KN"; units[7]="KW"; units[8]="KW";

      //generating the report
      PdfWriter wr = null;
       Document doc = new Document();


      try{
          //fos = new FileOutputStream(new File(filename)); 



          PdfPTable table = new PdfPTable(new float[] { 3, 2, 1 });
           table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
         table.addCell("Resistance and Powering parameter");
         table.addCell("Values");
         table.addCell("Units");
         table.setHeaderRows(1);
              PdfPCell[] cells = table.getRow(0).getCells(); 
         for (int j=0;j<cells.length;j++){
             cells[j].setBackgroundColor(BaseColor.GRAY);
         }
          for (int i=0;i<9;i++){
             table.addCell(new PdfPCell(new Paragraph(String.valueOf(para[i]))));
             table.addCell(new PdfPCell(new Paragraph(String.valueOf(val[i]))));
             table.addCell(new PdfPCell(new Paragraph(String.valueOf(units[i]))));
         }
           wr=PdfWriter.getInstance(doc, new FileOutputStream("report.pdf"));
         doc.open();
         Image in = Image.getInstance("app_icon.png");
         in.scaleToFit(100,100);
         //in.setAbsolutePosition(500,500);
         doc.add(in);
         doc.addTitle("Resistance and powering report");
         doc.addCreationDate();

         float w =520;//PageSize.A4.getWidth();
         float h =380;//*PageSize.A4.getHeight();


         //doc.add(new Paragraph("Resistance and powering report",FontFactory.getFont(FontFactory.TIMES_BOLD, 19,Font.BOLD,BaseColor.RED)));
         //doc.add(new Paragraph(new Date().toString()));
         doc.add(new Paragraph("Resistance and powering report",FontFactory.getFont(FontFactory.TIMES_ROMAN,18,Font.BOLD,BaseColor.ORANGE)));
         doc.add(new Paragraph(new Date().toString()));
         doc.add(new Paragraph("**********************************************************************************************"));

          doc.add(table);
          //doc.newPage();
           doc.add(new Paragraph("The effective power graph against the speed is shown below",FontFactory.getFont(FontFactory.TIMES_ITALIC,14,Font.ITALIC)));

          PdfContentByte tem = wr.getDirectContent();
          PdfTemplate tl = tem.createTemplate(w,h);
          Graphics2D gd =new PdfGraphics2D(tl,w,h,new DefaultFontMapper());
          Rectangle2D r = new Rectangle2D.Double(0,0,w,h);
          chart.draw(gd, r);

                  gd.dispose();
          Image im = Image.getInstance(tl);

          doc.add(im);
           /*Image inm = Image.getInstance("app_icon.png");
               in.setAbsolutePosition(490,100);
               wr.getDirectContent().addImage(in);
               doc.add(inm);*/

         doc.close(); }catch(Exception ex){
         }

  try{   

SwingController con= new SwingController();
SwingViewBuilder fac = new SwingViewBuilder(con);
JPanel jp =fac.buildViewerPanel();
con.getDocumentViewController().setAnnotationCallback(

new org.icepdf.ri.common.MyAnnotationCallback(con.getDocumentViewController()));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(jp);
con.openDocument("report.pdf");
frame.setIconImage(Toolkit.getDefaultToolkit().getImage("app_icon.png"));
frame.pack();

frame.setVisible(true);
  }
  catch(Exception ex){
  ex.printStackTrace();
  }

     // Desktop.getDesktop().open(new File("report.pdf"));



    }
4

0 回答 0