微信营销 网站建设,网页设计教程课本,网站的模版可以换吗,宁波建筑信息平台之前使用过mupdf库#xff0c;能够成功显示pdf#xff0c;但是我用着有BUG#xff0c;不太理解它的代码#xff0c;搞了好久都不行。后面又试了其他库#xff0c;如pdfium、popler、下载了很多例程#xff0c;都跑不起来#xff01;后面偶然得知xpdf库#xff0c;看起来… 之前使用过mupdf库能够成功显示pdf但是我用着有BUG不太理解它的代码搞了好久都不行。后面又试了其他库如pdfium、popler、下载了很多例程都跑不起来后面偶然得知xpdf库看起来应该容易编译因此这里主要是针对xpdf库的编译。 目前状态终于成功了2023-10-06直接看章节3即可 20231006_222307 一、官网
Download Xpdf and XpdfReader
官网有大致的介绍以及最新版本的xpdf源码的下载链接。但是没有具体讲怎么移植xpdf。
二、windows下的xpdf的编译
2.1、准备windows下的编译环境
我的编译环境
win10操作系统
vs2015社区版
qt版本qt5.9.5 在官网下载工具链。如下图红色框中所示点击后即可下载。这个压缩包是linux下的格式解压需要费点功夫。 下载并解压后放在xpdf源码目录下如下图所示。 2.2、编译freetype
在如下图的路径双击使用VS打开freetype.sln我的VS是vs2015社区版选择Release和win32后点击运行进行编译编程出dll文件。由于dll不能直接运行因此会报如下的错误忽略即可。
编译完成在 如下的路径下即可看到dll和lib文件。
工程路径\freetype-2.12.0\builds\windows\vc2010
编译结构路径\freetype-2.12.0\objs 在xpdf源码目录新建文件夹freetype将刚才生成的lib和dll文件拷贝到该文件夹中就完成了freetype的编译。 2.3、编译lcms
在如下图路径打开lcms的工程右键点击lcms2_DLL将其设为启动项目选择Release和win32后点击运行进行编译编程出dll文件。
工程路径\lcms2-2.12\Projects\VC2015
编译结构路径\lcms2-2.12\bin 在xpdf源码目录新建文件夹lcms将刚才生成的lib和dll文件拷贝到该文件夹中就完成了lcms的编译。 2.4、编译zlib
zlib-1.2.12版本有点bug需要先处理一下。
1、拷贝zlib-1.2.11去网上下载一个中的masmx76到contrib目录下
2、修改代码 1修改函数uLong ZEXPORT crc32_combine(crc1, crc2, len2) z_off_t len2改为z_off64_t len2; 2修改函数uLong ZEXPORT crc32_combine_gen(len2) z_off_t len2改为z_off64_t len2 3修改函数uLong crc32_combine_op(crc1, crc2, op)
改为uLong ZEXPORT crc32_combine_op(crc1, crc2, op) 3、右键zlibvc设置 SAFESEH 映像是不安全的异常处理程序关闭 完成 后开始正式的编译。
在如下图路径打开zlib的工程选择Release和win32后点击运行进行编译编程出dll文件。
工程路径\zlib-1.2.12\contrib\vstudio\vc14
编译结构路径\zlib-1.2.12\contrib\vstudio\vc14\x86\ZlibDllRelease 在xpdf源码目录新建文件夹zlib将刚才生成的lib和dll文件拷贝到该文件夹中就完成了zlib的编译。 如果出现异常情况
问题1.没有bld_ml32.bat
编译器报错详情 问题解决查看contrib目录下确实没有masmx86拷贝zlib-1.2.11中的masmx86和masmx64到contrib目录下问题解决。
问题2.实参的字节长度不同于以前的调用或引用
编译器报错详情如下 问题解决在crc32.c中修改如下内容
1.修改函数uLong ZEXPORT crc32_combine(crc1, crc2, len2) uLong crc1; uLong crc2; z_off_t len2;为z_off64_t len2; 2.修改函数1.uLong ZEXPORT crc32_combine_gen(len2) z_off_t len2;为z_off64_t len2 3.修改
uLong crc32_combine_op(crc1, crc2, op)为
uLong ZEXPORT crc32_combine_op(crc1, crc2, op) 问题3模块对于 SAFESEH 映像是不安全的。
使用Release编译忽略其他编译警告编译通过。
2.5、编译libpng
libpng的编译以来zlib因此需要将zlib的源码放在libpng源码的同级目录前面已经放过了
打开zlib.props文件修改zlib的路径和版本放在同级目录就不需要修改路径修改版本就行 在如下图路径打开libpng的工程右键点击libpng将其设为启动项目选择Release和win32后点击运行进行编译编程出dll文件。
工程路径\libpng-1.6.35\projects\vstudio
编译结构路径\libpng-1.6.35\projects\vstudio\Release 在xpdf源码目录新建文件夹libpng将刚才生成的lib和dll文件拷贝到该文件夹中就完成了libpng的编译。
2.6、编译xpdf
2.6.1 设置编译参数
(1) 在xpdf源码目录下新建bulid文件夹
(2) 打开vs2015的命令提示符工具看你的vs版本并进入build路径ctrlc后在命令框右键即可粘贴 输入如下命令设置各个库的包含路径和动态库的路径
cmake -G NMake Makefiles -DCMAKE_BUILD_TYPERelease -DFREETYPE_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/freetype/freetype.dll -DFREETYPE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/freetype-2.12.0 -DPNG_PNG_INCLUDE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/libpng-1.6.35 -DPNG_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/libpng/libpng16.dll -DZLIB_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/zlib/zlibwapi.dll -DZLIB_INCLUDE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/zlib .. 我的结果如下
E:\qt5.9.5\userfile\20231005\xpdf-4.04\buildcmake -G NMake Makefiles -DCMAKE_BUILD_TYPERelease -DFREETYPE_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/freetype/freetype.dll -DFREETYPE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/freetype-2.12.0 -DPNG_PNG_INCLUDE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/libpng-1.6.35 -DPNG_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/libpng/libpng16.dll -DZLIB_LIBRARYE:/qt5.9.5/userfile/20231005/xpdf-4.04/zlib/zlibwapi.dll -DZLIB_INCLUDE_DIRE:/qt5.9.5/userfile/20231005/xpdf-4.04/zlib ..
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: F:/vs2015/VC/bin/cl.exe
-- Check for working C compiler: F:/vs2015/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: F:/vs2015/VC/bin/cl.exe
-- Check for working CXX compiler: F:/vs2015/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for mkstemp
-- Looking for mkstemp - not found
-- Looking for mkstemps
-- Looking for mkstemps - not found
-- Looking for popen
-- Looking for popen - not found
-- Performing Test HAVE_STD_SORT
-- Performing Test HAVE_STD_SORT - Success
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for fseek64
-- Looking for fseek64 - not found
-- Looking for _fseeki64
-- Looking for _fseeki64 - found
-- Found FreeType (old-style includes): E:/qt5.9.5/userfile/20231005/xpdf-4.04/freetype/freetype.dll
-- Found ZLIB: E:/qt5.9.5/userfile/20231005/xpdf-4.04/zlib/zlibwapi.dll
-- Found PNG: E:/qt5.9.5/userfile/20231005/xpdf-4.04/libpng/libpng16.dll (found version 1.6.35)
-- Qt5 found
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: E:/qt5.9.5/userfile/20231005/xpdf-4.04/build
2.6.2 开始编译
在命令框输入
nmake
我失败在如下这一步2023-10-05 三、xpdf库在windows上新建QT工程
如需源码请上闲鱼搜索科技代码小卖部 3.1 新建一个新工程
在qtcreator下新建工程如下图XPDFDemo20231006New4_04
3.2 拷贝头文件
1拷贝freetype库的头文件到新工程目录下
在freetype库的源码下拷贝整个include文件夹到新工程目录。 2拷贝freetype库的库文件lib和dll到新工程目录下
在新工程目录下新建lib文件夹拷贝编译后的freetype库文件到该路径下编译方法见前面的2.2小节 3拷贝xpdf的头文件到新工程目录下
将xpdf库源码中的相关头文件拷贝到新工程目录下新建一个aconf.h文件将下面的代码拷贝到里面源码里只有aconf.h.in需要编译才能生成aconf.h如想自行编译见2.6小节在build文件夹下编译后会生成aconf.h文件 /** aconf.h** This file is modified by cmake.** Copyright 2002-2015 Glyph Cog, LLC*/#ifndef ACONF_H
#define ACONF_H#include aconf2.h/** Use A4 paper size instead of Letter for PostScript output.*/
#define A4_PAPER 1/** Do not allow text selection.*/
#define NO_TEXT_SELECT 0/** Include support for OPI comments.*/
#define OPI_SUPPORT 1/** Enable multithreading support.*/
#define MULTITHREADED 0/** Enable C exceptions.*/
#define USE_EXCEPTIONS 1/** Use fixed point (instead of floating point) arithmetic.*/
#define USE_FIXEDPOINT 1/** Enable support for CMYK output.*/
#define SPLASH_CMYK 1/** Enable support for DeviceN output.*/
#define SPLASH_DEVICEN 1/** Enable support for highlighted regions.*/
#define HIGHLIGHTED_REGIONS 1/** Full path for the system-wide xpdfrc file.*/
//SYSTEM_XPDFRC_DEFINE/** Directory to use for the ${DATADIR} variable in the xpdfrc config* file.*/
//XPDFRC_DATADIR_DEFINE/** Various include files and functions.*/
#define HAVE_MKSTEMP 1
#define HAVE_MKSTEMPS 1
#define HAVE_POPEN 1
#define HAVE_STD_SORT 1
#define HAVE_FSEEKO 0
#define HAVE_FSEEK64 0
#define HAVE_FSEEKI64 1
#define _FILE_OFFSET_BITS 64
#define _LARGE_FILES 1
#define _LARGEFILE_SOURCE 1/** This is defined if using FreeType 2.*/
#define HAVE_FREETYPE_H 1/** This is defined if using D-Type 4.*/
#define HAVE_DTYPE4_H 0/** This is defined if using libpaper.*/
#define HAVE_PAPER_H 0/** This is defined if using libfontconfig.*/
#define HAVE_FONTCONFIG 0/** Defined if the Splash library is avaiable.*/
#define HAVE_SPLASH 0/** Defined if using lcms2.*/
#define HAVE_LCMS 0/** Defined for evaluation mode.*/
#define EVAL_MODE 1/** Defined when building the closed source XpdfReader binary.*/
#define BUILDING_XPDFREADER 0#endif
4拷贝xpdf例程到新工程中
将xpdf库源码中的xpdf-qt文件夹拷贝到新工程目录下。 3.3 配置pro文件
删除core和gui模块添加QT库networkprintsupport和axcontainer。如下图所示 添加头文件和库文件的检索路径 3.4 添加已有文件到新工程
在Header上右键选择Add Existing Directory勾选所有需要导入的文件批量完成导入。 在默认的基础上把2个rc资源文件也勾选上如下图所示。 3.5 删除多余文件
由于例程没有用qt界面编辑器且自带main函数因此需要将原新建工程的以下文件删除
main.cpp
mainwindow.h
mainwindow.cpp
mainwindow.ui
删除后的工程结构如下图所示。 3.6 修改源码
源码还有点错误需要修改。先点击运行进行编译会报如下的错误。 1修改XpdfViewer.cc
打开XpdfViewer.cc文件添加头文件
#include time.h 2修改XpdfApp.cc
由于字符集的问题需要将XpdfApp.cc中的void XpdfApp::readPagesFile() 函数整个换为下方的代码进行字符转换。
char * wchar2char(const wchar_t* szUnicodeString)
{UINT nCodePage 936; //GB2312int nLengthWideCharToMultiByte(nCodePage,0,szUnicodeString,-1,NULL,0,NULL,NULL);char* pBuffernew char[nLength1];WideCharToMultiByte(nCodePage,0,szUnicodeString,-1,pBuffer,nLength,NULL,NULL);pBuffer[nLength]0;return pBuffer;}wchar_t * char2wchar(const char* cchar)
{wchar_t *m_wchar;int len MultiByteToWideChar( CP_ACP ,0,cchar ,strlen( cchar), NULL,0);m_wchar new wchar_t[len1];MultiByteToWideChar( CP_ACP ,0,cchar,strlen( cchar),m_wchar,len);m_wchar[len] \0 ;return m_wchar;
}void XpdfApp::readPagesFile() {// construct the file name (first time only)if (savedPagesFileName.isEmpty()) {
#ifdef _WIN32 wchar_t wpath[MAX_PATH];// char path[MAX_PATH];if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,SHGFP_TYPE_CURRENT, wpath) ! S_OK) {return;}//char path[MAX_PATH];char* pathwchar2char(wpath);savedPagesFileName QString::fromLocal8Bit(path);savedPagesFileName.append(/xpdf);CreateDirectory(char2wchar(savedPagesFileName.toLocal8Bit().constData()), NULL);savedPagesFileName.append(/xpdf.pages);// char path[MAX_PATH];
// if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
// SHGFP_TYPE_CURRENT, path) ! S_OK) {
// return;
// }
// savedPagesFileName QString::fromLocal8Bit(path);
// savedPagesFileName.append(/xpdf);
// CreateDirectory(savedPagesFileName.toLocal8Bit().constData(), NULL);
// savedPagesFileName.append(/xpdf.pages);
#elseGString *path getHomeDir();savedPagesFileName QString::fromUtf8(path-getCString());delete path;savedPagesFileName.append(/.xpdf.pages);
#endif}// no change since last read, so no need to re-readif (savedPagesFileTimestamp.isValid() QFileInfo(savedPagesFileName).lastModified() savedPagesFileTimestamp) {return;}// mark all entries invalidfor (int i 0; i maxSavedPageNumbers; i) {savedPageNumbers[i].fileName.clear();savedPageNumbers[i].pageNumber 1;}// read the fileFILE *f openFile(savedPagesFileName.toUtf8().constData(), rb);if (!f) {return;}char buf[1024];if (!fgets(buf, sizeof(buf), f) ||strcmp(buf, xpdf.pages-1\n) ! 0) {fclose(f);return;}int i 0;while (i maxSavedPageNumbers fgets(buf, sizeof(buf), f)) {int n (int)strlen(buf);if (n 0 buf[n-1] \n) {buf[n-1] \0;}char *p buf;while (*p ! *p) {p;}if (!*p) {continue;}*p \0;savedPageNumbers[i].pageNumber atoi(buf);savedPageNumbers[i].fileName QString::fromUtf8(p);i;}fclose(f);// save the timestampsavedPagesFileTimestamp QFileInfo(savedPagesFileName).lastModified();
}
3完成后又会报如下图的错误
png.h是libpng库里的头文件如果不需要pdf转html转txt等功能将把对应的.cc文件删掉。如果需要就要编译libpng库并导入对应的头文件。我这里不需要这些高级的功能就直接删掉了需要删掉的文件如下
HTMLGen.cc
pdftopng.cc
删除后重新执行qmake命令然后点击运行。 4完成后又会报如下图的错误 这是因为前面说的的高级功能每个都有main函数并能生成各自的exe文件从而导致main函数重复了。把他们都删除掉需要删除的文件如下
pdfdetach.cc
pdffonts.cc
pdfimages.cc
pdfinfo.cc
pdftohtml.cc
pdftoppm.cc
pdftops.cc
pdftotext.cc
同样完成后重新执行qmake命令然后点击运行。 3.6 xpdf库的使用 前面设置好xpdf库的配置就已经完成了已经可以开始使用了。点击运行即弹出程序。ENJOY 四、xpdf库的自用
如需源码请上闲鱼搜索科技代码小卖部
4.1 打开pdf文件