I can create a heat file that will create pdf. My program should work:
- entering data into frame1
- click on the frame1 calculation button
- output of the window Frame3 on which the results of the calculation are visible (text + picture + print button)
- After pressing the button on Frame3 - "qwe", it is supposed to create pdf on disk D.
The program works correctly in eclipsce, but when exporting the item with the creation of pdf does not work.
import java.awt.AWTEventMulticaster; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.math.BigDecimal; import java.math.RoundingMode; import javax.swing.ImageIcon; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.ToolTipManager; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.JTableHeader; import java.io.File; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.font.PDFont; import org.apache.pdfbox.pdmodel.font.PDType0Font; --- some code --- final JFrame Frame3 = new JFrame(); Frame3.setResizable(false); Frame3.setVisible(true); Frame3.setTitle("Расчет"); Frame3.setBackground(new Color(224, 255, 255)); Frame3.getContentPane().setBackground(new Color(240, 250, 255)); Frame3.getContentPane().setFont(new Font("Arial", 0, 16)); Frame3.setSize(raz_x_f, raz_y_f); Frame3.setDefaultCloseOperation(2); Frame3.getContentPane().setLayout(null); Frame3.setLocationRelativeTo(null); RoundedButton Button_pdf = new RoundedButton("qwe"); Button_pdf.setBackground(new Color(190, 220, 255)); Button_pdf.setFont(new Font("Arial", 1, 16)); Button_pdf.setBounds(raz_y_f-50, 20, 100, 26); Frame3.getContentPane().add(Button_pdf); Button_pdf.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { press = press + 1; try { PDDocument document = new PDDocument(); PDPage page = new PDPage(PDRectangle.A4); document.addPage(page); PDPage page0 = document.getPage(0); PDPageContentStream contentStream = new PDPageContentStream(document, page0); PDFont font = PDType0Font.load( document, new File("src/resources/FreeSans.ttf") ); contentStream.setLeading(14.5f); contentStream.beginText(); contentStream.setFont(font, 12); contentStream.newLineAtOffset(25, 800); contentStream.showText("1"); contentStream.newLine(); contentStream.showText("2"); contentStream.newLineAtOffset(200, 00); contentStream.showText(String.valueOf(Double.parseDouble(textField_1.getText()))); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("3"); contentStream.newLineAtOffset(200, 00); contentStream.showText(String.valueOf(Double.parseDouble(textField_2.getText()))); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("4"); contentStream.newLineAtOffset(200, 00); contentStream.showText(String.valueOf(Double.parseDouble(textField_3.getText()))); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("5"); contentStream.newLineAtOffset(200, 00); contentStream.showText(String.valueOf(L_tr)); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("6"); contentStream.newLineAtOffset(200, 00); contentStream.showText(comboBox_2st); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("7"); contentStream.newLineAtOffset(200, 00); contentStream.showText(comboBox_3st); contentStream.newLine(); contentStream.newLineAtOffset(-200, 00); contentStream.showText("8"); contentStream.newLineAtOffset(200, 00); contentStream.showText(comboBox_4st); contentStream.newLine(); contentStream.newLine(); contentStream.endText(); contentStream.close(); document.save("D:/result" + press + ".pdf"); document.close(); JOptionPane.showMessageDialog(Frame3, "pdf done"); } catch (IOException e1) { e1.printStackTrace(); } } });