欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

使用XPDF将PDF转换为HTML的实现步骤

程序员文章站 2023-11-24 20:21:10
使用XPDF将PDF转换为HTML的实现步骤...
1、下载xpdf最新版本,地址:http://www.foolabs.com/xpdf/download.html
我下载的是xpdf-3.02pl2-win32.zip
2、下载中文支持包
我下载的是xpdf-chinese-simplified.tar.gz
3、下载pdftohtml支持包
地址:http://sourceforge.net/projects/pdftohtml/
我下载的是:pdftohtml-0.39-win32.tar.gz
4、解压调试
1) 先将xpdf-3.02pl2-win32.zip解压,解压后的内容可根据需要进行删减,如果只需要转换为txt格式,其他的
exe文件可以删除,只保留pdftotext.exe,以此类推;
2) 然后将xpdf-chinese-simplified.tar.gz解压到刚才xpdf-3.02pl2-win32.zip的解压目录;
3) 将pdftohtml-0.39-win32.tar.gz解压,pdftohtml.exe解压到xpdf-3.02pl2-win32.zip的解压目录;
4) 目录结构:
+---[x:\xpdf]
|-------各种转换用到的exe文件
|
|-------xpdfrc
|
+------[x:\xpdf\xpdf-chinese-simplified]
|
http://www.javaeye.com/forums 1.6 word/excel/pdf文件转换成html整理
|
+-------很多转换时需要用到的字符文件
xpdfrc:此文件是用来声明转换字符集对应路径的文件
5) 修改xpdfrc文件(文件原名为sample-xpdfrc)
修改文件内容为:
#----- begin chinese simplified support package
cidtounicode adobe-gb1 xpdf-chinese-simplified\adobe-gb1.cidtounicode
unicodemap iso-2022-cn xpdf-chinese-simplified\iso-2022-cn.unicodemap
unicodemap euc-cn xpdf-chinese-simplified\euc-cn.unicodemap
unicodemap gbk xpdf-chinese-simplified\gbk.unicodemap
cmapdir adobe-gb1 xpdf-chinese-simplified\cmap
tounicodedir xpdf-chinese-simplified\cmap
fontdir c:\windows\fonts
displaycidfonttt adobe-gb1 c:\windows\fonts\simhei.ttf
#----- end chinese simplified support package
6) 创建bat文件pdftohtml.bat(放置的路径不能包含空格)
内容为:
@echo off
set folderpath=%1
set filepath=%2
cd /d %folderpath%
pdftohtml -enc gbk %filepath%
exit
http://www.javaeye.com/forums 1.6 word/excel/pdf文件转换成html整理
7) 创建类
public class convertpdf
{
private static string input_path;
private static string project_path;
public static void converttohtml(string file, string project)
{
input_path = file;
project_path = project;
if(checkcontenttype()==0)
{
tohtml();
}
}
private static int checkcontenttype()
{
string type = input_path.substring(input_path.lastindexof(".") + 1, input_path.length())
.tolowercase();
if (type.equals("pdf"))
return 0;
else
return 9;
}
private static void tohtml()
{
if(new file(input_path).isfile())
{
try
{
string cmd = "cmd /c start x:\\pdftohtml.bat \"" + project_path + "\" http://www.javaeye.com/forums 1.6 word/excel/pdf文件转换成html整理
runtime.getruntime().exec(cmd);
}
catch (ioexception e)
{
e.printstacktrace();
}
}
}
}
string cmd = "....";此处代码是调用创建的bat文件进行转换
8) 测试转换
public static void main(string[] args)
{
convertpdf.converttohtml("c:\\test.pdf", "x:\\xpdf");
}
相关标签: XPDF pdf HTML