QT编译Xpdf

这里使用Xpdf源码实现pdf阅读器,纯源码编译,无需dll,无需安装第三方pdf阅读器。

先参考本博客的《QT编译bzip2和zlib》、《QT编译libpng》、《QT编译FreeType和Little CMS》完成这些依赖库的编译。

下载xpdf源码。复制以下文件到xpdflib文件夹中,其中aconf.h.in修改文件名为aconf.h。

再将aconf.h修改为下面所示(我这里没有使用Little CMS,如有需要,请自行添加源文件并将以下文件中相应的条件编译改为#define HAVE_LCMS 1)。

/*
 * 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 1
#define HAVE_FSEEK64 1
#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

最后将这些库的源文件,放在新建的QT工程目录中,我这里的工程名为Xpdf。

先将lpng/pngtest.c删除,因为这里有main函数,会与xpdf的main函数冲突。

再将xpdflib/xpdf文件夹中的下图的同名.cc文件的main函数屏蔽。

因为这里的文件是分别对应一个命令行工具,所以每个.cc文件都包含了main函数。

可以使用条件编译,像下面这样,也可以直接删掉。

#if 0
void main() {
}
#endif

在.pro中添加(下面为一部分的pro文件,其中.c、.cc、.h等文件的信息没有贴出来,因为太多了)

这里添加了QT += axcontainer,是因为xpdf使用了ole32.dll的函数,需要用到COM组件。

QT += widgets
QT += network
QT += axcontainer
CONFIG += c++11 console
CONFIG -= app_bundle

RESOURCES += \
    xpdflib/xpdf-qt/icons.qrc

DISTFILES += \
    xpdflib/xpdf-qt/xpdf-icon.ico

INCLUDEPATH += \
freetype/include \
lpng \
xpdflib/fofi \
xpdflib/goo \
xpdflib/splash \
xpdflib/xpdf \
xpdflib/xpdf-qt \
xpdflib

其中运行的是xpdf.cc中的main函数。

最终结果,如下图所示,生成了XpdfReader,可以打开pdf,显示书签。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值