pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gstöttner Siegfried <siegfried.gstoett...@sbg.ac.at>
Subject AW: pdf viewer needed
Date Thu, 21 Jul 2016 10:49:01 GMT
Hi John!

Thank you for your quick reply. Here is my code for having multiple labels inside a VBox,
which is located in a ScrollPane - with one problem inside the loop...

    @FXML
    private Button button;
    @FXML
    private Label label;
    @FXML
    private VBox scrollBox;
//    @FXML
//    private ScrollPane scrollPane;

        BufferedImage bufImage = null;
        WritableImage image = null;
        Label labelGraphics = new Label();
        Label labelGraphics2 = new Label();

            PDDocument doc = PDDocument.load(file);
            int countPages = doc.getNumberOfPages();
            PDFRenderer renderer = new PDFRenderer(doc);

            // approach two or more pages per document - for testing only
            bufImage = renderer.renderImage(0, scale);
            image = SwingFXUtils.toFXImage(bufImage, null);
            scrollBox.getChildren().add(labelGraphics);
            labelGraphics.setGraphic(new ImageView(image));

            bufImage = renderer.renderImage(1, scale);
            image = SwingFXUtils.toFXImage(bufImage, null);
            scrollBox.getChildren().add(labelGraphics2);
            labelGraphics2.setGraphic(new ImageView(image));

            // one label per pdf-page
            for (int i = 0; i < countPages; i++) {
                bufImage = renderer.renderImage(i, scale);
                image = SwingFXUtils.toFXImage(bufImage, null);
                scrollBox.getChildren().add(new Label("labGraph" + i));
                // how to access Label named "labGraph" + i
                // to do next acion setGraphic()?
                
            }

            doc.close();

The static approach for testing works. But how can i access the dynamically created Label
to proceed ahed with "'labGraph + i'.setGraphic(new ImageView(image));"?

Next problem: graphics are rendered at different sizes according to the content of the document.
How could i get the renderer to compute an image from any document  that fits by width in
my VBox?

Thank's.
Thank's to Tilman for quickly replying too.

Kind regards,
Siegfried
-
Siegfried Gstöttner
siegfried.gstoettner@sbg.ac.at

-----Ursprüngliche Nachricht-----
Von: John Hewson [mailto:john@jahewson.com] 
Gesendet: Dienstag, 19. Juli 2016 19:12
An: users@pdfbox.apache.org
Betreff: Re: pdf viewer needed


> On 19 Jul 2016, at 05:34, Gstöttner Siegfried <siegfried.gstoettner@sbg.ac.at>
wrote:
> 
> Hi!
> 
> I am pretty new to java and currently working on an application for printing serial letters
in JavaFX. I would like to give the user an overview of the result in a simple pdf-viewer.
Like that one shown in an example prior to ver2.0. Could anybody tell me how to implement
this with the actual libry? Examples missing or i could not find them. Are there any experiences
with usage of Java FX8 Swingnode class to display such a viewer? Thank you very much.

Assuming you already have a PDDocument, and a Label named “pageView”, you can render individual
pages into the Label as follows:

PDFRenderer renderer = new PDFRenderer(doc); BufferedImage bufImage = renderer.renderImage(0);
Image image = SwingFXUtils.toFXImage(bufImage, null); pageView.setGraphic(new ImageView(image));

I’d recommend taking this approach and letting JavaFX handle any scrolling of the Label.
You can then have multiple labels for multiple pages, or a single label and next/prev page
buttons.

— John

> Kind regards,
> Siegfried
> -
> Siegfried Gstöttner
> siegfried.gstoettner@sbg.ac.at
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

Mime
View raw message