Test d'affichage PDF

-> Fonctionnel (voir PDFTest.java)
This commit is contained in:
LucasV-IUT
2021-11-28 00:33:17 +01:00
parent c77b21a384
commit e86d3f41b3
18 changed files with 74 additions and 188 deletions
+10 -56
View File
@@ -23,17 +23,7 @@ import java.io.IOException;
* @author Lucàs VABRE
* @author Noé VILLENEUVE
*/
public class Page {
/**
* Indice de la page
*/
private final int index;
/**
* Label contenant limage de la page
*/
private final JLabel image;
public class Page extends JLabel {
/**
* Hauteur de la page
@@ -45,16 +35,6 @@ public class Page {
*/
private int largeur;
/**
* Position X de la page dans son panel
*/
private int positionX;
/**
* Position Y de la page dans son panel
*/
private int positionY;
/**
* Crée une page virtuellement pour lafficher avec java swing
*
@@ -70,11 +50,7 @@ public class Page {
throw new IllegalArgumentException();
}
this.index = index;
this.image = generateImage(document);
positionX = 0;
positionY = 0;
this.setIcon(generateImage(document, index));
}
/**
@@ -98,44 +74,22 @@ public class Page {
* @return JLabel contenant la page sous forme dimage
* @throws IOException En cas derreur de lecture
*/
private JLabel generateImage(PDDocument document) throws IOException {
private ImageIcon generateImage(PDDocument document, int index) throws IOException {
PDFRenderer pdfRenderer = new PDFRenderer(document);
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(this.index,
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(index,
300,
ImageType.RGB);
this.largeur = bufferedImage.getWidth();
this.hauteur = bufferedImage.getHeight();
this.largeur = bufferedImage.getWidth() / 2;
this.hauteur = bufferedImage.getHeight() / 2;
ImageIcon icon = new ImageIcon(
System.out.println(largeur + "x" + hauteur);
final ImageIcon imageIcon = new ImageIcon(
bufferedImage.getScaledInstance(largeur, hauteur,
Image.SCALE_SMOOTH));
JLabel result = new JLabel("", SwingConstants.LEADING);
result.setIcon(icon);
return result;
}
/**
* Positionne la page dans son Panel
*
* @param positionX Position X de la page
* @param positionY Position Y de la page
*/
public void setPosition(int positionX, int positionY) {
this.positionX = positionX;
this.positionY = positionY;
image.setLocation(positionX, positionY);
}
/**
* @return Le label contenant limage de la page
*/
public JLabel getImage() {
return image;
return imageIcon;
}
/**