mirror of
https://github.com/LucasVbr/LecteurPdfDoubleAffichage.git
synced 2026-12-05 18:30:49 +00:00
Init V2
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package lecteur_pdf_swing.pdf;
|
||||
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PdfLoader {
|
||||
PDDocument document;
|
||||
PDFRenderer renderer;
|
||||
|
||||
public PdfLoader(File file) throws IOException {
|
||||
document = PDDocument.load(file);
|
||||
renderer = new PDFRenderer(document);
|
||||
}
|
||||
|
||||
public int getNbPages() {
|
||||
return document.getNumberOfPages();
|
||||
}
|
||||
|
||||
public BufferedImage renderPage(int pageIndex, float scale) throws IOException {
|
||||
if (pageIndex < 0 || pageIndex >= this.getNbPages()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return renderer.renderImage(pageIndex, scale);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
document.close();
|
||||
} catch(IOException ignored) {}
|
||||
}
|
||||
|
||||
public void load(File file) {
|
||||
try {
|
||||
document = PDDocument.load(file);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user