private static void processPage( PdfFile file, Document document, int i, int scaleInt, boolean isthumbnail) { float scale = scaleInt / 100.0f; float rotation = 0f; PDimension size = document.getPageDimension(i, rotation, scale); // double dpi = Math.sqrt((size.getWidth() * size.getWidth()) + // (size.getHeight() * size.getHeight())) // / Math.sqrt((8.5 * 8.5) + (11 * 11)); // if (dpi < (targetDPI - 0.1)) { // scale = (float) (targetDPI / dpi); size = document.getPageDimension(i, rotation, scale); // } int pageWidth = (int) (size.getWidth()); int pageHeight = (int) (size.getHeight()); BufferedImage image = new BufferedImage(pageWidth, pageHeight, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = image.createGraphics(); document.paintPage(i, g, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, rotation, scale); g.dispose(); if (!isthumbnail) { String pageImage = getPageImagePath(file, i, scaleInt, isthumbnail); ImageUtil.saveJPEG(image, pageImage); Logger.debug("Page File Path: %s", pageImage); } else { String pageThumbnail = getPageImagePath(file, i, scaleInt, isthumbnail); BufferedImage thumbnail = ImageUtil.thumbnail(image, 140, 160, false, false); ImageUtil.saveJPEG(thumbnail, pageThumbnail); Logger.debug("Page Thumbnail Path: %s", pageThumbnail); models.Page page = models.Page.find("file= ? and page = ?", file, i).first(); if (page == null) { page = new models.Page(); page.file = file; page.page = i; } page.content = document.getPageText(i).toString(); page.width = pageWidth; page.height = pageHeight; page.save(); } Logger.debug("process page %s", i); }
@Override protected Bitmap doInBackground(Void... params) { Bitmap img = ImageUtil.getUrlImage(MyApplication.getPhone()); return img; }