本文整理汇总了Java中org.apache.pdfbox.rendering.ImageType类的典型用法代码示例。如果您正苦于以下问题:Java ImageType类的具体用法?Java ImageType怎么用?Java ImageType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImageType类属于org.apache.pdfbox.rendering包,在下文中一共展示了ImageType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateImage
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
@Override
public File generateImage(PDDocument pdDocument) throws FileNotFoundException {
File imageFile = null;
try{
PDFRenderer pdfRenderer = new PDFRenderer(pdDocument);
for(int x = 0;x < pdDocument.getNumberOfPages();x++){
BufferedImage bImage = pdfRenderer.renderImageWithDPI(x,300, ImageType.RGB);
ImageIOUtil.writeImage(bImage,String.format(folderPath + "/template_image.%s" ,"jpg"),300);
}
pdDocument.close();
imageFile = new File(folderPath + "/template_image.jpg");
}catch (IOException e){
e.printStackTrace();
}
return imageFile;
}
示例2: savePdfPageAsPNG
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
/**
* Renders PDF page with DPI specified in settings and saves it in specified directory.
*
* @param renderer PDF renderer instance
* @param page page number
* @param outputDir output directory
* @throws IOException
*/
private void savePdfPageAsPNG(PDFRenderer renderer, int page, Path outputDir) throws IOException {
BufferedImage bim;
synchronized (this) {
bim = renderer.renderImageWithDPI(page, settings.getPdfRenderingDpi(), ImageType.RGB);
}
Path outPath = outputDir.resolve(Paths.get("page_" + (page + 1) + ".png"));
ImageIOUtil.writeImage(bim, outPath.toString(), settings.getPdfRenderingDpi());
}
示例3: savePdfTablePagesDebugImages
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
/**
* Saves debug images of PDF pages from specified range and saves them in specified directory.
*
* @param document PDF document instance
* @param startPage first page in range to process (first page == 1)
* @param endPage last page in range
* @param outputDir destination directory
* @throws IOException
*/
public void savePdfTablePagesDebugImages(PDDocument document, int startPage, int endPage, Path outputDir) throws IOException {
TableExtractor debugExtractor = new TableExtractor(settings);
PDFRenderer renderer = new PDFRenderer(document);
for (int page = startPage - 1; page < endPage; ++page) {
PdfTableSettings debugSettings = PdfTableSettings.getBuilder()
.setDebugImages(true)
.setDebugFileOutputDir(outputDir)
.setDebugFilename("page_" + (page + 1))
.build();
debugExtractor.setSettings(debugSettings);
BufferedImage bi;
synchronized (this) {
bi = renderer.renderImageWithDPI(page, settings.getPdfRenderingDpi(), ImageType.RGB);
}
debugExtractor.getTableBoundingRectangles(bufferedImage2GrayscaleMat(bi));
}
}
示例4: toImageFiles
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
public static List<File> toImageFiles(File pdfFile, int resolution) throws Exception {
PDDocument document = PDDocument.load(pdfFile);
PDFRenderer pdfRenderer = new PDFRenderer(document);
/*
List<PDPage> pages = new LinkedList<PDPage>();
for (int i=0; i < document.getDocumentCatalog().getPages().getCount(); i++) {
pages.add( document.getDocumentCatalog().getPages().get(i) );
}
*/
File tmpDir = new File(Constants.getWorkTmpDir() + "/" + PdfConvertUtils.class.getSimpleName()
+ "/" + System.currentTimeMillis() + "/");
FileUtils.forceMkdir( tmpDir );
List<File> files = new LinkedList<File>();
//int len = String.valueOf(pages.size()+1).length();
int len = String.valueOf(document.getDocumentCatalog().getPages().getCount()+1).length();
//for (int i=0; i<pages.size(); i++) {
for (int i=0; i<document.getDocumentCatalog().getPages().getCount(); i++) {
String name = StringUtils.leftPad(String.valueOf(i+1), len, "0");
BufferedImage bufImage = pdfRenderer.renderImageWithDPI(i, resolution, ImageType.RGB);
File imageFile = new File( tmpDir.getPath() + "/" + name + ".png" );
FileOutputStream fos = new FileOutputStream(imageFile);
ImageIOUtil.writeImage(bufImage, "png", fos, resolution);
fos.flush();
fos.close();
files.add(imageFile);
}
document.close();
tmpDir = null;
return files;
}
示例5: getImg
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
public BufferedImage getImg(InputStream pdf) {
try {
PDDocument document = PDDocument.load(pdf);
PDFRenderer pdfRenderer = new PDFRenderer(document);
BufferedImage bufferedImage = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB);
return ImageThumbnailCreator.resizeImage(bufferedImage);
} catch (Exception e) {
throw new CantCreateThumbnailException(e);
}
}
示例6: parsePdfTablePages
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
/**
* Parses range of PDF pages and returns list of lists of rows containing cell texts.
*
* @param document PDF document instance
* @param startPage first page in range to parse (first page == 1)
* @param endPage last page in range
* @return List of pages
* @throws IOException
*/
public List<ParsedTablePage> parsePdfTablePages(PDDocument document, int startPage, int endPage) throws IOException {
List<ParsedTablePage> out = new ArrayList<>();
PDFRenderer renderer = new PDFRenderer(document);
for (int page = startPage - 1; page < endPage; ++page) {
BufferedImage bi;
synchronized (this) {
bi = renderer.renderImageWithDPI(page, settings.getPdfRenderingDpi(), ImageType.RGB);
}
ParsedTablePage parsedTablePage = parsePdfTablePage(bi, document.getPage(page), page + 1);
out.add(parsedTablePage);
}
return out;
}
示例7: renderPage
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
public static void renderPage(String pdfPath, String outPath, int pageNumber, Rectangle area,
boolean drawTextChunks, boolean drawSpreadsheets, boolean drawRulings, boolean drawIntersections,
boolean drawColumns, boolean drawCharacters, boolean drawArea, boolean drawCells,
boolean drawUnprocessedRulings, boolean drawProjectionProfile, boolean drawClippingPaths,
boolean drawDetectedTables) throws IOException {
PDDocument document = PDDocument.load(new File(pdfPath));
ObjectExtractor oe = new ObjectExtractor(document);
Page page = oe.extract(pageNumber + 1);
if (area != null) {
page = page.getArea(area);
}
PDPage p = document.getPage(pageNumber);
BufferedImage image = Utils.pageConvertToImage(p, 72, ImageType.RGB);
Graphics2D g = (Graphics2D) image.getGraphics();
if (drawTextChunks) {
debugTextChunks(g, page);
}
if (drawSpreadsheets) {
debugSpreadsheets(g, page);
}
if (drawRulings) {
debugRulings(g, page);
}
if (drawIntersections) {
debugIntersections(g, page);
}
if (drawColumns) {
debugColumns(g, page);
}
if (drawCharacters) {
debugCharacters(g, page);
}
if (drawArea) {
g.setColor(Color.ORANGE);
drawShape(g, area);
}
if (drawCells) {
debugCells(g, area, page);
}
if (drawUnprocessedRulings) {
debugNonCleanRulings(g, page);
}
if (drawProjectionProfile) {
debugProjectionProfile(g, page);
}
if (drawClippingPaths) {
// TODO: Enable when oe.clippingPaths is done
//drawShapes(g, oe.clippingPaths,
// new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, new float[] { 3f }, 0f));
}
if (drawDetectedTables) {
debugDetectedTables(g, page);
}
document.close();
ImageIO.write(image, "jpg", new File(outPath));
}
示例8: pageConvertToImage
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
public static BufferedImage pageConvertToImage(PDPage page, int dpi, ImageType imageType) throws IOException {
try (PDDocument document = new PDDocument()) {
document.addPage(page);
PDFRenderer renderer = new PDFRenderer(document);
document.close();
return renderer.renderImageWithDPI(0, dpi, imageType);
}
}
示例9: testJPEG2000DoesNotRaise
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
@Test
public void testJPEG2000DoesNotRaise() throws IOException {
PDDocument pdf_document = PDDocument.load(new File("src/test/resources/technology/tabula/jpeg2000.pdf"));
PDPage page = pdf_document.getPage(0);
Utils.pageConvertToImage(page, 360, ImageType.RGB);
}
示例10: call
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
@Override
public Boolean call() throws IOException, InterruptedException, SearchLibException {
if (context.ghostScript == null) {
final BufferedImage image = context.pdfRenderer.renderImageWithDPI(currentPage, 300, ImageType.RGB);
if (ImageUtils.checkIfManyColors(image)) {
final HocrPage hocrPage = context.hocrPdf.createPage(currentPage, image.getWidth(),
image.getHeight());
hocrPage.addImage(doOcr(context.ocr, context.lang, image));
} else
emptyPageImages.incrementAndGet();
} else {
ocrImageGhostcript(context, currentPage + 1);
}
return true;
}
示例11: getThumbnail
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
/**
* Take a Snapshot from PDFObject.
*
* @param media
* the MediaObject
* @param seek
* position to take a snapshot
* @param maxWidth
* maximum output width
* @param maxHeight
* maximum output height
* @param keepAspect
* set to keep aspect ratio
*/
@SuppressWarnings("unchecked")
public synchronized byte[] getThumbnail(MCRMediaObject media, long seek, int maxWidth, int maxHeight,
boolean keepAspect)
throws Exception {
byte[] imageInByte = null;
try (PDDocument pdf = PDDocument.load(new File(media.folderName + media.fileName))) {
PDPageTree pages = pdf.getDocumentCatalog().getPages();
PDFRenderer pdfRenderer = new PDFRenderer(pdf);
BufferedImage image = pdfRenderer.renderImageWithDPI((int) seek, 96, ImageType.RGB);
int[] scaledSize = ((MCRPDFObject) media).getScaledSize(maxWidth, maxHeight, keepAspect);
BufferedImage resized = new BufferedImage(scaledSize[0], scaledSize[1], image.getType());
Graphics2D g = resized.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g.drawImage(image, 0, 0, scaledSize[0], scaledSize[1], 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "png", baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
} catch (Exception e) {
throw new Exception(e.getMessage());
}
return imageInByte;
}
示例12: call
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
@Override
public Result call() throws Exception {
BufferedImage image = renderer.renderImage(pageIndex, 1f, ImageType.BINARY);
return detector.detect(image);
}
示例13: loadPdfFile
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
private void loadPdfFile() {
if (presentationFile == null) {
return;
}
if (loadPdfThread != null) {
loadPdfThread.interrupt();
loadPdfThread = null;
}
loadPdfThread = new Thread(() -> {
try (PDDocument pdfDocument = PDDocument.load(presentationFile)) {
PdfRenderer renderer = new PdfRenderer(pdfDocument);
ScreenDevice screenDevice = (ScreenDevice) presentationScreenComboBox.getSelectedItem();
GraphicsDevice selectedDevice = screenDevice.getDevice();
pagesCount = pdfDocument.getNumberOfPages();
presentationLoadingProgressBar.setMaximum(pagesCount);
presentationLoadingProgressBar.setValue(0);
// presentationLoadingProgressBar.setStringPainted(false);
presentationMap.clear();
currentPage = 0;
for (int processedPage = 0; processedPage < pagesCount; ++processedPage) {
presentationLoadingProgressBar.setString(String.format("%d/%d", processedPage, pagesCount));
PDRectangle rect = pdfDocument.getPage(processedPage).getCropBox();
float width = selectedDevice.getDisplayMode().getWidth();
float height = selectedDevice.getDisplayMode().getHeight();
float screenProportion = width / height;
float scale;
if (screenProportion <= rect.getWidth() / rect.getHeight()) {
scale = width / rect.getWidth();
} else {
scale = height / rect.getHeight();
}
BufferedImage bi = renderer.renderImage(processedPage, scale * 2.0f, ImageType.RGB);
if (Thread.interrupted()) {
return;
}
presentationMap.put(processedPage, bi);
presentationLoadingProgressBar.setValue(processedPage + 1);
checkStartPresentationButtonEnabled();
refreshFullscreenPage();
}
presentationLoadingProgressBar.setString(String.format("%d/%d", pagesCount, pagesCount));
} catch (IOException ex) {
JOptionPane.showMessageDialog(this, String.format("Wystąpił wyjątek:\n%s", ex.getLocalizedMessage()), "Błąd", JOptionPane.ERROR_MESSAGE);
}
});
loadPdfThread.start();
}
示例14: process
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
public static BufferedImage process(InputStream pdfFile) {
BufferedImage output = null;
try (PDDocument pdfDocument = PDDocument.load(pdfFile)) {
PDFRenderer renderer = new PDFRenderer(pdfDocument);
int pageCount = pdfDocument.getNumberOfPages();
if (pageCount > 0) {
int width = 0;
int height = -1;
BufferedImage[] pdfPages = new BufferedImage[pageCount];
for (int pageNo = 0; pageNo < pageCount; ++pageNo) {
pdfPages[pageNo] = renderer.renderImageWithDPI(pageNo, 200.0f, ImageType.RGB);
if (pdfPages[pageNo].getWidth() > width) {
width = pdfPages[pageNo].getWidth();
}
height += pdfPages[pageNo].getHeight() + 1;
}
output = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = output.createGraphics();
g.setColor(Color.red);
int currentHeight = 0;
for (int pageNo = 0; pageNo < pageCount; ++pageNo) {
if (pageNo > 0) {
g.drawLine(0, currentHeight, width, currentHeight);
++currentHeight;
}
g.drawImage(pdfPages[pageNo],
(width - pdfPages[pageNo].getWidth()) / 2,
currentHeight,
null);
currentHeight += pdfPages[pageNo].getHeight();
}
g.dispose();
}
} catch (Exception ex) {
throw new RuntimeException("Exception converting pdf to image: ", ex);
}
return output;
}
示例15: createImageFromPage
import org.apache.pdfbox.rendering.ImageType; //导入依赖的package包/类
/**
* Renders the given page as an RGB image.
* @param document the document containing the page.
* @param pageIndex the index of the page to render.
* @param resolution the image resolution.
* @return the rendered image
* @throws IOException by pdfbox
*/
public static BufferedImage createImageFromPage(final PDDocument document, int pageIndex, final int resolution) throws IOException {
PDFRenderer pdfRenderer = new PDFRenderer(document);
return pdfRenderer.renderImageWithDPI(pageIndex, resolution, ImageType.RGB);
}