PDF_TO_picture

// PDF_TO_picture.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include "fitz.h"

using namespace std;

#define LOG(format, ...)  	\
{								\
    fprintf(stderr, "[DEBUG] [%s:%s:%d] " format "", \
    __FILE__, __FUNCTION__ , __LINE__, ##__VA_ARGS__);     \
}

int main()
{
    std::cout << "Hello World!\n";

//	const char* input = "123.pdf";
	const char* input = "605072021425200010636.pdf";
	float zoom = 0.0, rotate = 0.0;
	int page_number = 0, page_count = 0;
	fz_context* ctx = nullptr;
	fz_document* doc = nullptr;
	fz_pixmap* pix = nullptr;
	fz_matrix ctm;
//	int x, y;

	page_number = 0;
	zoom = 100*10;
	rotate = 0;

	/* Create a context to hold the exception stack and various caches. */
	ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
	if (!ctx)
	{
		fprintf(stderr, "cannot create mupdf context\n");
		return EXIT_FAILURE;
	}

	/* Register the default file types to handle. */
	fz_try(ctx)
		fz_register_document_handlers(ctx);
	fz_catch(ctx)
	{
		fprintf(stderr, "cannot register document handlers: %s\n", fz_caught_message(ctx));
		fz_drop_context(ctx);
		return EXIT_FAILURE;
	}

	/* Open the document. */
	fz_try(ctx)
		doc = fz_open_document(ctx, input);
	fz_catch(ctx)
	{
		fprintf(stderr, "cannot open document: %s\n", fz_caught_message(ctx));
		fz_drop_context(ctx);
		return EXIT_FAILURE;
	}

	/* Count the number of pages. */
	fz_try(ctx)
		page_count = fz_count_pages(ctx, doc);
	fz_catch(ctx)
	{
		fprintf(stderr, "cannot count number of pages: %s\n", fz_caught_message(ctx));
		fz_drop_document(ctx, doc);
		fz_drop_context(ctx);
		return EXIT_FAILURE;
	}

	if (page_count < 0)
	{
		fprintf(stderr, "page count %d\n", page_count);
		fz_drop_document(ctx, doc);
		fz_drop_context(ctx);
		return EXIT_FAILURE;
	}

	/* Compute a transformation matrix for the zoom and rotation desired. */
	/* The default resolution without scaling is 72 dpi. */
	ctm = fz_scale(zoom / 100, zoom / 100);
	ctm = fz_pre_rotate(ctm, rotate);

	int nTemp_page_count = 0;
	std::string strFileName = "";
	while (page_count - nTemp_page_count>0)
	{
		LOG("page_count:%d,nTemp_page_count%d\n",page_count,nTemp_page_count);
		LOG("page_count-nTemp_page_count:%d\n", page_count - nTemp_page_count);
		/* Render page to an RGB pixmap. */
		fz_try(ctx)
			pix = fz_new_pixmap_from_page_number(ctx, doc, nTemp_page_count, ctm, fz_device_rgb(ctx), 0);
		fz_catch(ctx)
		{
			fprintf(stderr, "cannot render page: %s\n", fz_caught_message(ctx));
			fz_drop_document(ctx, doc);
			fz_drop_context(ctx);
			return EXIT_FAILURE;
		}

		nTemp_page_count++;
		std::to_string(nTemp_page_count) + ".png";
		fz_save_pixmap_as_png(ctx, pix, strFileName.c_str());
		strFileName = "";
	}

	/* Clean up. */
	fz_drop_pixmap(ctx, pix);
	fz_drop_document(ctx, doc);
	fz_drop_context(ctx);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MFC是Microsoft Foundation Classes的缩写,是一种用于开发Windows桌面应用程序的框架。要在MFC中显示PDF文件,可以使用Adobe Acrobat Reader的COM组件。 首先,需要在项目中引入Adobe Acrobat Reader的COM组件。可以通过右键单击项目名称,选择“添加” -> “引用”,然后在COM选项卡中搜索并选择“Adobe Acrobat 7.0 Browser Control Type Library”(或更高版本)。 接下来,在需要显示PDF文件的对话框或窗口类中,添加一个控件来承载PDF文件。可以选择一个或多个控件,例如静态文本框、Picture控件等。在需要显示PDF的位置,添加一个控件。 在对话框或窗口类的成员函数中,使用以下代码来加载和显示PDF文件: ```cpp // 声明变量 CAxWindow pdfControl; // PDF控件名称 CRect rect; // 控件矩形位置和大小 // 获取控件位置和大小 GetDlgItem(IDC_PDF_CONTROL)->GetClientRect(&rect); // 创建PDF控件 pdfControl.CreateControl(CLSID_AcroPDF.PDF, NULL, WS_CHILD | WS_VISIBLE, rect, this, IDC_PDF_CONTROL); // 打开PDF文件 pdfControl.QueryControl()->put_Src(L"C:\\path\\to\\your\\file.pdf"); ``` 以上代码中,首先声明了一个名为`pdfControl`的CAxWindow对象来承载PDF文件。然后,通过GetDlgItem函数获取控件的位置和大小。接下来,使用CreateControl函数创建PDF控件,并通过put_Src函数加载指定路径的PDF文件。 最后,将控件的ID设置为IDC_PDF_CONTROL(可以根据实际情况修改)。在对应的对话框资源文件中,添加一个静态文本框或Picture控件,并将其ID设置为IDC_PDF_CONTROL。 通过上述方法,可以在MFC应用程序中显示PDF文件。请确保系统中已安装Adobe Acrobat Reader,并根据实际路径修改代码中的文件路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值