Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

java - I want to build a PDF doc, using Glen K. Peterson's Pdf Layout Manager, but I'm stuck at building a table

I've decided to use Glen K Peterson's Pdf Layout Manager available on GitHub(https://github.com/GlenKPeterson/PdfLayoutManager) to generate PDF documents with my app, I've imported the source files and the pom.xml dependencies and everything, it's working just fine. The problem is, I'm trying to build a table in one of the documents I want to generate with a button click. I have no idea how to extract(use) the TableBuilder, as I'm getting the error message inside my JDeveloper IDE, that the class has private access.

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();
    try {
        PDPage page = new PDPage();
        document.addPage(page);
        PDFont font = PDType1Font.COURIER;
        PDPageContentStream contents = new PDPageContentStream(document, page);
        contents.beginText();
        contents.setFont(font, 14);
        contents.newLineAtOffset(50, 500);
        Coord coordinate = new Coord(10, 700);
        PdfLayoutMgr pageMgr = PdfLayoutMgr.newRgbPageMgr();
        LogicalPage locatieTabel = pageMgr.logicalPageStart();
        TableBuilder tabel = new TableBuilder(locatieTabel, coordinate); // Getting the error at this point
        contents.newLineAtOffset(10, 700);
        contents.showText(tabel.toString());
        contents.endText();
        contents.close();
    } 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);
        }
    }
    jLabelAverstismenteVerMet.setText("<html><center>Datele au fost salvate cu succes!</center></html>");
}//GEN-LAST:event_jBtnSalvareVerMetActionPerformed

I thought of changing the type of access permission from private to public, for the TableBuilder, but I don't think, that's the way it's actually supposed to work... Is there any other way, I can build the table I need, without resorting to changing the access modifier, inside the TableBuilder class??

question from:https://stackoverflow.com/questions/65847118/i-want-to-build-a-pdf-doc-using-glen-k-petersons-pdf-layout-manager-but-im

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You try to use

TableBuilder tabel = new TableBuilder(locatieTabel, coordinate); // Getting the error at this point

But that constructor is private

    private TableBuilder(LogicalPage lp, Coord tl) {
        logicalPage = lp; topLeft = tl;
    }

I.e. you are not meant to use it. Unfortunately there also is no JavaDoc indicating what you should use instead. But looking at the TableBuilder source a bit beyond that constructor, you'll find immediately following this:

    public static TableBuilder of(LogicalPage lp, Coord tl) {
        return new TableBuilder(lp, tl);
    }

Thus, instead of your direct constructor call you should use this factory method:

TableBuilder tabel = TableBuilder.of(locatieTabel, coordinate);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...