Skip to content

Commit

Permalink
Opening PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Sep 28, 2022
1 parent 69d17dd commit b8f359b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/luwrain/app/viewer/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public App(String arg)
this.arg = arg;
}

@Override protected AreaLayout onAppInit()
@Override protected AreaLayout onAppInit() throws IOException
{
if (arg != null && !arg.isEmpty())
load(arg);
final ViewPdf viewPdf = createPdfView();
viewPdf.show();
this.mainLayout = new MainLayout(this);
return mainLayout.getAreaLayout();
}
Expand All @@ -71,7 +73,7 @@ private void load(String file)
*/
}

private ViewPdf createPdfView()
private ViewPdf createPdfView() throws IOException
{
return new ViewPdf(getLuwrain()){
@Override void inaccessible() { getLuwrain().playSound(Sounds.ERROR); }
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/viewer/Extension.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/luwrain/app/viewer/ViewImage.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/luwrain/app/viewer/ViewPdf.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -26,7 +26,7 @@
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.canvas.GraphicsContext;
//import javafx.embed.swing.SwingFXUtils;
import javafx.embed.swing.SwingFXUtils;
import javafx.application.Platform;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
Expand Down Expand Up @@ -59,10 +59,10 @@ abstract class ViewPdf
private double offsetX = 0;
private double offsetY = 0;

ViewPdf(Luwrain luwrain)
ViewPdf(Luwrain luwrain) throws IOException
{
this.luwrain = luwrain;
this.doc = null;//PDDocument.load(file);
this.doc = PDDocument.load(new File("/tmp/proba.pdf"));
this.rend = new PDFRenderer(doc);
Log.debug(LOG_COMPONENT, "PDF renderer created");
}
Expand All @@ -76,7 +76,7 @@ abstract class ViewPdf
abstract void announceZoomIn();
abstract void announceZoomOut();

public void show()
void show()
{
luwrain.showGraphical((control)->{
try {
Expand All @@ -89,10 +89,7 @@ public void show()
}
catch(Throwable e)
{
Log.error(LOG_COMPONENT, "unable to initialize the PDF preview:" + e.getClass().getName() + ":" + e.getMessage());
e.printStackTrace();
this.canvas = null;
return null;
throw new RuntimeException(e);
}
});
}
Expand Down Expand Up @@ -297,7 +294,7 @@ private Image makeImage(int pageNum, float scale)
Log.error(LOG_COMPONENT, "unable to render a PDf page:" + e.getClass().getName() + ":" + e.getMessage());
return null;
}
final Image image = null;//SwingFXUtils.toFXImage(pageImage, null);
final Image image = SwingFXUtils.toFXImage(pageImage, null);
Log.debug(LOG_COMPONENT, "image " + String.format("%.2f", image.getWidth()) + "x" + String.format("%.2f", image.getHeight()));
return image;
}
Expand Down

0 comments on commit b8f359b

Please sign in to comment.