I can create a heat file that will create pdf. My program should work:

  1. entering data into frame1
  2. click on the frame1 calculation button
  3. output of the window Frame3 on which the results of the calculation are visible (text + picture + print button)
  4. 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(); } } }); 

Closed due to the fact that off-topic participants Kromster , aleksandr barakin , 0xdb , user192664, Roman C 7 Nov '18 at 10:23 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, 0xdb, Community Spirit, Roman C
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Have you heard about StackTrace? - Igor Kudryashov
  • Thank you so much. Found a mistake. Did not find the style of the text. - Roman

1 answer 1

It was enough to add the text style to the root and change the path to: PDFont font = PDType0Font.load (document, new File ("FreeSans.ttf"));