-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#172 Change the library "com-sun-pdfview" to "pdfbox" for pdf to png
- Loading branch information
1 parent
93eb3cd
commit 6c9e7e0
Showing
7 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/org/support/project/knowledge/parser/impl/PdfSlideShowParserOnPdfbox.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.support.project.knowledge.parser.impl; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.apache.pdfbox.pdmodel.PDDocument; | ||
import org.apache.pdfbox.pdmodel.PDPage; | ||
import org.apache.pdfbox.util.ImageIOUtil; | ||
import org.support.project.common.exception.ParseException; | ||
import org.support.project.knowledge.parser.SlideShowParser; | ||
|
||
public class PdfSlideShowParserOnPdfbox implements SlideShowParser { | ||
|
||
@Override | ||
public void parse(File inputFile, File outputDir) throws ParseException { | ||
try { | ||
/* | ||
* Solution for the 1.8 version: | ||
*/ | ||
PDDocument document = PDDocument.loadNonSeq(inputFile, null); | ||
List<PDPage> pdPages = document.getDocumentCatalog().getAllPages(); | ||
int page = 0; | ||
for (PDPage pdPage : pdPages) { | ||
++page; | ||
BufferedImage bim = pdPage.convertToImage(BufferedImage.TYPE_INT_RGB, 300); | ||
ImageIOUtil.writeImage(bim, outputDir.getAbsolutePath() + "/" + page + ".png", 300); | ||
} | ||
document.close(); | ||
|
||
/* | ||
* Solution for the 2.0 version: | ||
PDDocument document = PDDocument.load(inputFile); | ||
PDFRenderer pdfRenderer = new PDFRenderer(document); | ||
for (int page = 0; page < document.getNumberOfPages(); ++page) { | ||
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB); | ||
// suffix in filename will be used as the file format | ||
ImageIOUtil.writeImage(bim, outputDir.getAbsolutePath() + "/" + (page + 1) + ".png", 300); | ||
} | ||
document.close(); | ||
*/ | ||
|
||
} catch (IOException e) { | ||
throw new ParseException(e); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.