当前位置:   article > 正文

xpdf 实现pdf转图片_s050000l.pfb 安装

s050000l.pfb 安装

一、下载

下载当前系统对应的安装包,中文简体安装包,官方下载地址
在这里插入图片描述
下载后的安装包:
在这里插入图片描述
配置好的安装包:
链接:https://pan.baidu.com/s/1XCQUbNwjF_KqYL-Tqpy5lw
提取码:s462

二、安装配置

windows:

假设安装路径为:D:\pdftool\xpdf
1、解压xpdf-tools-win-4.03.zip,并将bin64目录下所有文件和doc目录下的 sample-xpdfrc 复制到 D:\pdftool\xpdf目录;
2、将 sample-xpdfrc 改名为xpdfrc(默认配置名称为xpdfrc);
3、解压xpdf-chinese-simplified.tar.gz和xpdf-t1fonts.tar.gz,并复制到 D:\pdftool\xpdf目录;
在这里插入图片描述
4、修改xpdfrc配置:
找到textEncoding UTF-8,将注释打开;
并在下面增加 textPageBreaks no 参数,表示pdf文档的两页间不加入分行符。
5、在最后面增加内容:

#------ 配置字体文件 ----
fontFile Symbol                D:/pdftool/xpdf/xpdf-t1fonts/s050000l.pfb
fontFile ZapfDingbats          D:/pdftool/xpdf/xpdf-t1fonts/d050000l.pfb

#----- begin Chinese Simplified support package (2011-sep-02)
cidToUnicode Adobe-GB1 D:/tool/xpdf/xpdf-chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN D:/tool/xpdf/xpdf-chinese-simplified/ISO-2022-CN.unicodeMap
unicodeMap EUC-CN D:/tool/xpdf/xpdf-chinese-simplified/EUC-CN.unicodeMap
unicodeMap GBK D:/tool/xpdf/xpdf-chinese-simplified/GBK.unicodeMap
cMapDir Adobe-GB1 D:/tool/xpdf/xpdf-chinese-simplified/CMap
toUnicodeDir D:/tool/xpdf/xpdf-chinese-simplified/CMap
#displayCIDFontTT Adobe-GB1 D:/xpdf/xpdf-chinese-simplified/CMap/gkai00mp.ttf 
#fontFileCC Adobe-GB1 /usr/..../gkai00mp.ttf
#----- end Chinese Simplified support package
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
Linux:

1、解压xpdf-tools-linux-4.03.tar.gz,并将bin64目录下所有文件和doc目录下的 sample-xpdfrc 复制到 /usr/local/bin/xpdf目录;
2、将 sample-xpdfrc 改名为xpdfrc(默认配置名称为xpdfrc);
3、解压xpdf-chinese-simplified.tar.gz和xpdf-t1fonts.tar.gz,并复制到 /usr/local/bin/xpdf目录;
在这里插入图片描述
4、修改xpdfrc配置:
找到textEncoding UTF-8,将注释打开,指定编码为UTF-8,并在下面增加 textPageBreaks no 参数,表示pdf文档的两页间不加入分行符。
5、在最后面增加内容:(相关配置本人根据需要已做过调整)

#------ 配置字体文件 ----
fontFile Symbol                 /usr/local/bin/xpdf/fonts/s050000l.pfb
fontFile ZapfDingbats           /usr/local/bin/xpdf/fonts/d050000l.pfb
#fontFile MicrosoftYaHei                /usr/local/bin/xpdf/fonts/generalFonts/MicrosoftYaHei.ttf
fontFile STSongStd-Light-UniGB-UCS2-H           /usr/local/bin/xpdf/fonts/generalFonts/STSong-Light-UniGB-UCS2-H.ttf
fontFile TimesNewRomanPSMT           /usr/local/bin/xpdf/fonts/generalFonts/TimesNewRomanPSMT.otf
# 字体包(可从上面百度网盘下载)
fontDir /usr/local/bin/xpdf/fonts/generalFonts


#----- begin Chinese Simplified support package (2011-sep-02)
cidToUnicode Adobe-GB1 /usr/local/bin/xpdf/xpdf-chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN /usr/local/bin/xpdf/xpdf-chinese-simplified/ISO-2022-CN.unicodeMap
unicodeMap EUC-CN /usr/local/bin/xpdf/xpdf-chinese-simplified/EUC-CN.unicodeMap
unicodeMap GBK /usr/local/bin/xpdf/xpdf-chinese-simplified/GBK.unicodeMap
cMapDir Adobe-GB1 /usr/local/bin/xpdf/xpdf-chinese-simplified/CMap
toUnicodeDir /usr/local/bin/xpdf/xpdf-chinese-simplified/CMap
#displayCIDFontTT Adobe-GB1 /usr/local/bin/xpdf/xpdf-chinese-simplified/CMap/gkai00mp.ttf
#fontFileCC Adobe-GB1 /usr/..../gkai00mp.ttf
#----- end Chinese Simplified support package
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

三、使用

1、windows执行命令:

D:\pdftool\xpdf\pdftopng.exe -f 1 -l 2 D:\temp\test.pdf D:\temp\testpng
解释:
-f 1 ----- 从第1页开始转换。
-l 2 ----- 转换至第2页结束,
D:\temp\test.pdf ----- 待转换的pdf文件
D:\temp\testpng ----- 生成的图片名前缀叫testpng 最终会以testpng-000001.png的形式生成在D:\temp\目录下
其他参数解释可执行D:\pdftool\xpdf\pdftopng.exe 查看

2、Linux执行命令:

cd /usr/local/bin/xpdf
需要给予执行权限:chomd 777 chmod 777 pdf*
./pdftopng -f 1 -l 1 /tmp/test.pdf /tmp/testpng
解释:
-f 1 是指从第一页开始。
-l 1 是指第一页结束,
/tmp/testpng是指生成的图片名前缀叫testpng 最终会以testpng-000001.png的形式生成在/tmp/目录下
其他参数解释可执行./pdftopng 查看

四、Java实现:

import org.apache.commons.lang.StringUtils;

import java.io.*;
import java.util.List;

/**
 * PDF转换工具类(xpdf : https://www.xpdfreader.com/download.html)
 *
 *
 * @Classname PDFConvert
 * @Description
 * @Date 2022/1/4 8:59
 * @Created by zhanyp
 */
public class PDFConvertUtils {


    /**
     * widows xpdf 安装路径
     */
    private static String win_path = "D:\\pdftool\\xpdf";
    private static String linux_path = "/usr/local/bin/xpdf";
    /**
     * -f 1 :第一页开始;
     * -l 1 :第一页结束;
     */
    private static String PDF_TO_PNG_CMD = "%s -f %s -l %s %s %s";

    /**
     * windows环境下pdf转png
     *
     * @Auther zhanyp
     * @Date 2022/1/4
     * @Param toolPath : xpdf安装目录 例如D:\pdftool\xpdf
     * @Param sourcePath : 源pdf文件 例如 D:\test.pdf
     * @Param targetPath : 目标png保存路径 D:\pdf\png
     * @Param pngName ;目标png图片名称 例如:test
     * @Param startPageNum : 开始页数 例如 1, 从第一页开始
     * @Param endPageNum : 结束页数 例如 3,第三页结束
     * @Return
     */
    public static void pdfToPngWin(String toolPath, String sourcePath, String targetPath, String pngName, Integer startPageNum, Integer endPageNum) {
        if (StringUtils.isBlank(toolPath)) {
            toolPath = win_path;
        }
        File dir = new File(targetPath);
        if (!dir.exists() && !dir.isDirectory()) {
            dir.mkdirs();
        }
        String targetName = targetPath + File.separator + pngName;
        String command = String.format(PDF_TO_PNG_CMD, toolPath + File.separator + "pdftopng.exe", startPageNum, endPageNum, sourcePath, targetName);
        System.out.println("执行命令:" + command);
        try {
            Runtime.getRuntime().exec(command);
            System.out.println("pdfToPng 成功");
        } catch (IOException e) {
            System.out.println("pdfToPng 失败");
            e.printStackTrace();
        }
    }

    /**
     * linux环境下pdf转png
     *
     * @Auther zhanyp
     * @Date 2022/1/4
     * @Param toolPath : xpdf安装目录 例如/usr/local/bin/xpdf
     * @Param sourcePath : 源pdf文件 例如 /tmp/pdftopng/a.pdf
     * @Param targetPath : 目标png保存路径 /tmp/pdftopng
     * @Param pngName ;目标png图片名称 例如:test
     * @Param startPageNum : 开始页数 例如 1, 从第一页开始
     * @Param endPageNum : 结束页数 例如 3,第三页结束
     * @Return
     */
    public static void pdfToPngLinux(String toolPath, String sourcePath, String targetPath, String pngName, Integer startPageNum, Integer endPageNum) {
        if (StringUtils.isBlank(toolPath)) {
            toolPath = linux_path;
        }
        File dir = new File(targetPath);
        if (!dir.exists() && !dir.isDirectory()) {
            dir.mkdirs();
        }
        String targetName = targetPath + File.separator + pngName;
        String command = String.format(PDF_TO_PNG_CMD, "./pdftopng", startPageNum, endPageNum, sourcePath, targetName);
        System.out.println("执行命令:" + command);
        Runtime run = Runtime.getRuntime();
        Process proc = null;
        BufferedReader in = null;
        PrintWriter out = null;
        try {
            proc = run.exec("/bin/bash", null, null);
            in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
            out.println("cd " + toolPath);
            out.println(command);
            // out.println("cd /home/test");
            // out.println("pwd");
            // out.println("rm -fr /home/proxy.log");
            out.println("exit");// 这个命令必须执行,否则in流不结束。
            proc.waitFor();
        } catch (Exception e) {
            System.out.println("pdf转图片异常:");
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
                if (proc != null) {
                    proc.destroy();
                }
            } catch (Exception e){

            }
        }
    }
    


    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        pdfToPngWin(win_path, "D:\\pdftool\\test\\a.pdf", "D:\\pdftool\\test", "aa", 1, 2);
        System.out.println(System.currentTimeMillis() - start);
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/198972
推荐阅读
相关标签
  

闽ICP备14008679号