mirror of
https://github.com/LucasVbr/LecteurPdfDoubleAffichage.git
synced 2026-05-16 09:05:34 +00:00
Ajout de la possibilité de zoom avec rechargerPDF()
This commit is contained in:
@@ -6,15 +6,12 @@
|
||||
|
||||
package lecteur_pdf.document;
|
||||
|
||||
import lecteur_pdf.affichage.Fenetre;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Définis virtuellement un fichier PDF
|
||||
@@ -36,7 +33,12 @@ public class PDF extends JPanel {
|
||||
*/
|
||||
private final PDDocument document;
|
||||
|
||||
private List pages;
|
||||
/**
|
||||
* Les pages du PDF sous forme de JLabel contenant des images
|
||||
*/
|
||||
private final Page[] pages;
|
||||
|
||||
private float zoom;
|
||||
|
||||
/**
|
||||
* Crée un document PDF qui est capable d’être affiché dans une fenêtre
|
||||
@@ -47,7 +49,8 @@ public class PDF extends JPanel {
|
||||
public PDF(File fichier) {
|
||||
try {
|
||||
this.document = PDDocument.load(fichier);
|
||||
pages = this.document.getDocumentCatalog().getAllPages();
|
||||
this.pages = new Page[document.getNumberOfPages()];
|
||||
this.zoom = 1.0f;
|
||||
|
||||
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
this.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||
@@ -59,32 +62,15 @@ public class PDF extends JPanel {
|
||||
/**
|
||||
* Charge toutes les pages du document PDF et les stocke dans le tableau
|
||||
*/
|
||||
public void loadPages(Fenetre fenetre, int zoom) {
|
||||
public void loadPages() {
|
||||
|
||||
|
||||
for (Object p : pages) {
|
||||
if (p instanceof PDPage pdPage) {
|
||||
try {
|
||||
this.add(new Page(pdPage, zoom));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
fenetre.validate();
|
||||
|
||||
/* Méthode asynchrone (Ne marche pas bien) */
|
||||
// new Thread(() -> {
|
||||
// try {
|
||||
// this.add(new Page(pdPage, zoom));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// fenetre.validate();
|
||||
// try {
|
||||
// Thread.sleep(50);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }).start();
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
try {
|
||||
pages[i] = new Page(document, i, zoom);
|
||||
this.add(pages[i]);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +83,8 @@ public class PDF extends JPanel {
|
||||
public int getNbPages() {
|
||||
return document.getNumberOfPages();
|
||||
}
|
||||
|
||||
public void setZoom(float zoom) {
|
||||
this.zoom = zoom;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user