【问题标题】:Pdf to image that support other language (not only english)支持其他语言的 PDF 到图像(不仅是英语)
【发布时间】:2016-06-13 07:48:55
【问题描述】:

我正在尝试使用 java 将 pdf 转换为图像,但是当我使用 pdf 渲染器将其转换时,图像文件中的文本呈现并且它不是英语语言无法读取,因为这里的图像 ->

public static void main(String[] args) {

    File file = new File("path file");
    RandomAccessFile raf;
    try {
        raf = new RandomAccessFile(file, "r");

        FileChannel channel = raf.getChannel();
        ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
        PDFFile pdffile = new PDFFile(buf);
        // draw the first page to an image
        int num = pdffile.getNumPages();
        for (int i = 1; i <= num; i++) {
            PDFPage page = pdffile.getPage(i);

            // get the width and height for the doc at the default zoom
            int width = (int) page.getBBox().getWidth();
            int height = (int) page.getBBox().getHeight();

            Rectangle rect = new Rectangle(0, 0, width, height);
            int rotation = page.getRotation();
            Rectangle rect1 = rect;
            if (rotation == 90 || rotation == 270)
                rect1 = new Rectangle(0, 0, rect.height, rect.width);

            // generate the image
            BufferedImage img = (BufferedImage) page.getImage(rect.width, rect.height, // width
                                                                                        // &
                                                                                        // height
                    rect1, // clip rect
                    null, // null for the ImageObserver
                    true, // fill background with white
                    true // block until drawing is done
            );

            ImageIO.write(img, "png", new File("path file" + i + ".png"));
        }
    } catch (FileNotFoundException e1) {
        System.err.println(e1.getLocalizedMessage());
    } catch (IOException e) {
        System.err.println(e.getLocalizedMessage());
    }
}

有人知道如何用英语以外的语言将 pdf 渲染成图像吗?

【问题讨论】:

    标签: java pdf


    【解决方案1】:

    那些小方框是“未知字符”字符。有可能您的 PDF 没有嵌入必要的字体并且您的系统没有它们......但如果它们在任何 ol PDF 查看器中看起来都很好(阅读器可以宽容),那可能不是它。

    过去,我使用了一个名为 GhostScript 的命令行程序。它是免费的/开源的,所以你可以直接下载它,在命令行上阅读,然后让 'er rip。哎呀,我几年前就用过它,所以现在它甚至可能有一些漂亮的用户界面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-08
      • 2015-03-27
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多