2021-01-29

Having an issue placing text & table on same PDF page using Boxable

I'm having an issue placing some text and a table on the same PDF doc page, using the Boxable library for building PDF tables! The document is generated fine, except that it's supposed to generate one single page, with both the text and the table right underneath(and later adding another separate table under the first table), what it's doing is placing the text and table on separate pages each!

Here's my code:

private void jBtnSalvareVerMetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSalvareVerMetActionPerformed
    // TODO add your handling code here:
    PDDocument document = new PDDocument();
    PDPage pagina = new PDPage(PDRectangle.A4);
    document.addPage(pagina);
    try {
        PDFontLike font = PDType0Font.load(document, new File("C:\\Oracle\\Middleware\\Oracle_Home\\jdeveloper\\mywork\\" +
                                                              "mywork\\DigitalizareLaboratorMetrologie\\project\\FisiereDLM\\" +
                                                              "FisiereAplicatie\\arial.ttf"));
        PDPageContentStream contents = new PDPageContentStream(document, pagina);
        contents.beginText();
        contents.setLeading(14.5f);
        contents.setFont((PDFont) font, 16);
        contents.moveTextPositionByAmount(50, 725);
        contents.drawString("S.C. Necom S.R.L");
        contents.moveTextPositionByAmount(0, -20);
        contents.drawString("Laborator Metrologie");
        contents.moveTextPositionByAmount(150, -60);
        contents.drawString("Comanda verificare metrologica");
        contents.moveTextPositionByAmount(12, -25);
        contents.drawString("Nr: "+jTextFieldNrVerMet.getText() + "   Data: " + jTextFieldDataVerMet.getText());
        contents.moveTextPositionByAmount(-60, -20);
        contents.endText();
        BaseTable table = new BaseTable(-60, pagina.getMediaBox().getHeight(), 70, pagina.getMediaBox().getWidth() - (2 * 50), 50,
                                        document, pagina, true, true);
        Row<PDPage> row = table.createRow(20);
        Cell<PDPage> cell;
        cell = row.createCell(50, "Denumire solicitant");
        cell.setAlign(HorizontalAlignment.LEFT);
        cell.setFontSize(15);
        cell = row.createCell(50, jTextFieldNumeSolicitant.getText());
        cell.setFontSize(15);
        cell.setFont(PDType0Font.load(document, new File("C:\\Oracle\\Middleware\\Oracle_Home\\jdeveloper\\mywork\\" +
                                                         "mywork\\DigitalizareLaboratorMetrologie\\project\\FisiereDLM\\" +
                                                         "FisiereAplicatie\\arial.ttf")));

        row = table.createRow(20);
        cell = row.createCell(50, "Date identificare");
        cell.setTextColor(Color.BLACK);
        cell.setFontSize(15);
        cell.setFont(PDType0Font.load(document, new File("C:\\Oracle\\Middleware\\Oracle_Home\\jdeveloper\\mywork\\" +
                                                         "mywork\\DigitalizareLaboratorMetrologie\\project\\FisiereDLM\\" +
                                                         "FisiereAplicatie\\arial.ttf")));
        cell.setAlign(HorizontalAlignment.LEFT);
        cell = row.createCell(50, "Adresa: " + jTextFieldAdresa.getText() + "<br>Cod fiscal: " +
                              jTextFieldCodFiscal.getText() + "<br>Cod IBAN: " + jTextFieldIBAN.getText());
        cell.setTextColor(Color.BLACK);
        cell.setFontSize(15);
        cell.setFont(PDType0Font.load(document, new File("C:\\Oracle\\Middleware\\Oracle_Home\\jdeveloper\\mywork\\" +
                                                         "mywork\\DigitalizareLaboratorMetrologie\\project\\FisiereDLM\\" +
                                                         "FisiereAplicatie\\arial.ttf")));
        cell.setAlign(HorizontalAlignment.LEFT);

        row = table.createRow(20);
        cell = row.createCell(50, "Persoana contact / Telefon");
        cell.setFontSize(15);
        cell.setAlign(HorizontalAlignment.LEFT);
        cell = row.createCell(50, jTextFieldPersoanaContact.getText());
        cell.setFontSize(15);
        table.draw();
        contents.close();
        document.save("C:\\Users\\Dragos\\Desktop\\Comanda de verificare metrologica.pdf");
        jLabelAverstismenteVerMet.setText("<html><center>Datele au fost salvate cu succes!</center></html>");
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(MeniuTaburi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } finally {
        try {
            document.close();
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(MeniuTaburi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
    }
}//GEN-LAST:event_jBtnSalvareVerMetActionPerformed

I've read on similar threads here on the site, that it may be because of a bug with the Boxable page rendering libraries, which are based on iText. Has anybody figured out how to get passed this?



from Recent Questions - Stack Overflow https://ift.tt/39omTYW
https://ift.tt/eA8V8J

No comments:

Post a Comment