最新有需求需要用C++ 打印PDF文件
首先要下载一个adobe reader 用adobe reader中的ocx来实现打印
下载地址自行百度 或者用本人的下载地址(adobe加源代码):https://download.youkuaiyun.com/download/immotal_xiaoqiang/11049468
开发环境联想E440笔记本+ vs2013 测试环境win7 64
首先新建一个MFC DIALOG工程
选择class wizard
选择第三个 MFC class form activeX Control
选择 adobe的ocx
点击确定后 会自动生成OCX对应的.h 和.cpp文件
在button1 添加单击事件 示例代码如下
#include "CAcroAXDocShim.h"
CAcroAXDocShim pdf;
//发送打印任务
void CPdfPrintMyTestDlg::OnBnClickedButton1()
{
BOOL bAdobeReaderCreated = pdf.Create("", WS_VISIBLE , CRect(0, 0, 1, 1),AfxGetMainWnd(), 1050);
if (!bAdobeReaderCreated)
{
::AfxMessageBox("创建PDF失败");
return;
}
if (!pdf.LoadFile("D:/2.pdf")) //loadfile是加载pdf
{
::AfxMessageBox("打开pdf文件失败.");
return;
}
pdf.printAllFit(TRUE); //打印 这里应该是异步去打印的
}
指定打印PDF第几页到第几页
把pdf.printAllFit(TRUE); 换pdf.printPages(2,3); 即打印PDF的第2页和第三页
仅此作为记录,如后续有新需求再补充!