You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Dean Schulze <de...@gmail.com> on 2017/12/19 18:05:35 UTC

How to display pdf in JavaFX using PDFBox 2.0.8

I need to display a .pdf file in a JavaFX application.  I've found various
examples of others doing this PDFBox 1.8 with

PDPage.convertToImage();

and then displaying the image.

But there is no PDPage.convertToImage() in PDFBox 2.0.  How do I display a
.pdf file in PDFBox 2.0?

Thanks.

Re: How to display pdf in JavaFX using PDFBox 2.0.8

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 20.12.2017 um 18:33 schrieb Dean Schulze:
> That worked, but the image it displayed was very mangled.  Most of the
> content of the .pdf was missing.

Save the BufferedImage into a .PNG file (ImageIO.write(...)). If that 
one is correct, then the problem is only related to JavaFX and it may be 
better to ask the question on stackoverflow (which as much details as 
possible, and without the pdfbox aspect). If the image is incorrect, 
then please share the PDF.

Tilman

>
>
> On Tue, Dec 19, 2017 at 12:01 PM, Claudius Teodorescu <
> claudius.teodorescu@gmail.com> wrote:
>
>> Hi,
>>
>>
>> It is displayed page by page, with a function like the following:
>>
>> public Image goToPage(int pageNumber) {
>> BufferedImage pageImage = null;
>> try {
>> pageImage = renderer.renderImage(pageNumber);
>>
>> } catch (IOException ex) {
>> Logger.getLogger(TAG).log(Level.SEVERE, null, ex);
>> }
>>
>> return SwingFXUtils.toFXImage(pageImage, null);
>> }
>> .
>>
>> The FXML correspondant:
>>
>> <ScrollPane fx:id="centerSourcePane" fitToHeight="true"
>> fitToWidth="true" pannable="true">
>> <content>
>> <StackPane>
>> <children>
>> <ImageView fx:id="contentSourcePane" cache="true" />
>> </children>
>> </StackPane>
>> </content>
>> </ScrollPane>
>>
>> Clauidus
>>
>> On Tue, Dec 19, 2017 at 8:05 PM, Dean Schulze <de...@gmail.com>
>> wrote:
>>
>>> I need to display a .pdf file in a JavaFX application.  I've found
>> various
>>> examples of others doing this PDFBox 1.8 with
>>>
>>> PDPage.convertToImage();
>>>
>>> and then displaying the image.
>>>
>>> But there is no PDPage.convertToImage() in PDFBox 2.0.  How do I display
>> a
>>> .pdf file in PDFBox 2.0?
>>>
>>> Thanks.
>>>
>>
>>
>> --
>> http://kuberam.ro
>>


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


Re: How to display pdf in JavaFX using PDFBox 2.0.8

Posted by Dean Schulze <de...@gmail.com>.
That worked, but the image it displayed was very mangled.  Most of the
content of the .pdf was missing.


On Tue, Dec 19, 2017 at 12:01 PM, Claudius Teodorescu <
claudius.teodorescu@gmail.com> wrote:

> Hi,
>
>
> It is displayed page by page, with a function like the following:
>
> public Image goToPage(int pageNumber) {
> BufferedImage pageImage = null;
> try {
> pageImage = renderer.renderImage(pageNumber);
>
> } catch (IOException ex) {
> Logger.getLogger(TAG).log(Level.SEVERE, null, ex);
> }
>
> return SwingFXUtils.toFXImage(pageImage, null);
> }
> .
>
> The FXML correspondant:
>
> <ScrollPane fx:id="centerSourcePane" fitToHeight="true"
> fitToWidth="true" pannable="true">
> <content>
> <StackPane>
> <children>
> <ImageView fx:id="contentSourcePane" cache="true" />
> </children>
> </StackPane>
> </content>
> </ScrollPane>
>
> Clauidus
>
> On Tue, Dec 19, 2017 at 8:05 PM, Dean Schulze <de...@gmail.com>
> wrote:
>
> > I need to display a .pdf file in a JavaFX application.  I've found
> various
> > examples of others doing this PDFBox 1.8 with
> >
> > PDPage.convertToImage();
> >
> > and then displaying the image.
> >
> > But there is no PDPage.convertToImage() in PDFBox 2.0.  How do I display
> a
> > .pdf file in PDFBox 2.0?
> >
> > Thanks.
> >
>
>
>
> --
> http://kuberam.ro
>

Re: How to display pdf in JavaFX using PDFBox 2.0.8

Posted by Claudius Teodorescu <cl...@gmail.com>.
Hi,


It is displayed page by page, with a function like the following:

public Image goToPage(int pageNumber) {
BufferedImage pageImage = null;
try {
pageImage = renderer.renderImage(pageNumber);

} catch (IOException ex) {
Logger.getLogger(TAG).log(Level.SEVERE, null, ex);
}

return SwingFXUtils.toFXImage(pageImage, null);
}
.

The FXML correspondant:

<ScrollPane fx:id="centerSourcePane" fitToHeight="true"
fitToWidth="true" pannable="true">
<content>
<StackPane>
<children>
<ImageView fx:id="contentSourcePane" cache="true" />
</children>
</StackPane>
</content>
</ScrollPane>

Clauidus

On Tue, Dec 19, 2017 at 8:05 PM, Dean Schulze <de...@gmail.com>
wrote:

> I need to display a .pdf file in a JavaFX application.  I've found various
> examples of others doing this PDFBox 1.8 with
>
> PDPage.convertToImage();
>
> and then displaying the image.
>
> But there is no PDPage.convertToImage() in PDFBox 2.0.  How do I display a
> .pdf file in PDFBox 2.0?
>
> Thanks.
>



-- 
http://kuberam.ro