一、下载XPDF工具包
win版 xpdf4win
arm版 xpdf4arm
解压pdf工具包,本例中将win版解压到"D:/xpdf"
arm版直接将压缩包放到工程的"资源/其他"目录下,在启动时执行解压即可
二、页面设计
如下图:(下面的大框是一个面板)
三、在窗体头文件自定义区块中增加一个定义
/*CUSTOM_CODE_BEGIN*/
PDFUtil *pdf;
/*CUSTOM_CODE_END*/
四、onLoad代码
void Frm01::onLoad(){
/**
* 参数1:解压后的文件夹。在这个文件夹下能找到pdftopng.exe等
* 参数2: PDF文件路径
* 参数3: 转换后png文件路径及文件前缀。示例中png将保存在d:/pdftool/xpdf文件夹下,生成的png文件名为stt-xxxxxx.png(xxxxxx为6位数字)
* 参数4: 面板控件,用于显示PDF内容
*/
#if __arm__
string result;
Util::exeSync("tar -xzf /customer/prm/res/others/pdf.tar.gz -C /customer/prm/res/others", "r", result);
Util::exeSync("chmod +x /customer/prm/res/others/pdftopng", "r", result);
Util::exeSync("chmod +x /customer/prm/res/others/pdfinfo", "r", result);
Util::exeSync("chmod +x /customer/prm/res/others/pdffonts", "r", result);
Util::exeSync("mv /customer/prm/res/others/libpng16.so.16.40.0 /customer/xttlib/libpng16.so.16", "r", result);
Util::exeSync("sync", "r", result);
//如将arm版的xpdf解压到工程目录的“资源/其他/xpdf”下
//如将readme.pdf也放在“资源/其他/xpdf”下
//如将转换后的文件放到“资源/其他/xpdf”下,用stt作为文件前缀
pdf = new PDFUtil("/customer/prm/res/others","/customer/prm/res/others/ApusIDEv2.1.0.pdf","/customer/usr/stt",wMPanel1);
pdf->first();
#else
//如将arm版的xpdf解压到“d:/xpdf下”
//如将readme.pdf也放在“d:/xpdf下”
//如将转换后的文件放到“d:/xpdf”下,用stt作为文件前缀
pdf = new PDFUtil("d:/xpdf","d:/xpdf/readme.pdf","d:/xpdf/stt",wMPanel1);
#endif
}
五、其他各按钮代码如下
void Frm01::wMButton1_clk_cb(uint16_t code, LvEvent e) {
/*wMButton1的点击事件(打开)*/
pdf->gotoPage(1);
}
void Frm01::wMButton8_clk_cb(uint16_t code, LvEvent e) {
/*wMButton8的点击事件(首页)*/
pdf->first();
}
void Frm01::wMButton9_clk_cb(uint16_t code, LvEvent e) {
/*wMButton9的点击事件(上一页)*/
pdf->back();
}
void Frm01::wMButton10_clk_cb(uint16_t code, LvEvent e) {
/*wMButton10的点击事件(下一页)*/
pdf->next();
}
void Frm01::wMButton11_clk_cb(uint16_t code, LvEvent e) {
/*wMButton11的点击事件(末页)*/
pdf->last();
}
void Frm01::wMButton14_clk_cb(uint16_t code, LvEvent e) {
/*wMButton14的点击事件(旋转)*/
pdf->rotate();
}
void Frm01::wMButton12_clk_cb(uint16_t code, LvEvent e) {
/*wMButton12的点击事件(放大)*/
pdf->zoom(1.25);
}
void Frm01::wMButton13_clk_cb(uint16_t code, LvEvent e) {
/*wMButton13的点击事件(缩小)*/
pdf->zoom(0.8);
}
屏上的使用
1.由于资源文件夹下只能下载文件,而不能下载文件夹,可将arm内容打包成tar.gz格式。
2.把这个压缩包放在"资源/其它"下
3.下载后解压:
3.1 cd /customer/prm/res/others/
3.2 tar -vfx a.tar.gz ,/customer/prm/res/others/目录内容如下