MuPDF的使用

MuPDF的使用

调用流程

// 获取上下文

fz_context context = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
if (!context)
return;
// register the default file types
fz_register_document_handlers(context);
// open document 路径为utf-8的路径
fz_try(context)
{
fz_document document = fz_open_document(context, filePath.toUtf8().data());
}

获取目录

//把fz_output out改下你想要的行式就可以获取了,从中获取想要的标题与数据
static void do_debug_outline(fz_output *out, fz_outline outline, int level)
{
int i;
while (outline)
{
for (i = 0; i < level; i++)
printf(out, “\t”);
fz_printf(out, “%s\t%d\n”, outline->title, outline->dest.kind == FZ_LINK_GOTO ? outline->dest.ld.gotor.page + 1 : 0);
if (outline->down)
do_debug_outline(out, outline->down, level + 1);
outline = outline->next;
}
}
fz_outline outline = fz_load_outline(context, document);
do_debug_outline(out, outline, 0);

搜索关键字

旧的接口调用:
//查找V1的位置,返回所在坐标
 

static fz_rect search_hit_bbox[5000] = { 0 };
int aa = fz_search_page_number(context, document, 0, “V1”, search_hit_bbox, 5000);


新的接口调用:(参考源码的调用)

//第二个参数代表页数
fz_page page = fz_load_page(doc, 0);
fz_display_list list = NULL;
fz_device* dev = NULL;
fz_text_page* text = NULL;
fz_cookie cookie = {0};
static fz_text_sheet* sheet = NULL;
const fz_matrix fz_identity = {1, 0, 0, 1, 0, 0};
sheet = fz_new_text_sheet(ctx);
text = fz_new_text_page(ctx);
dev = fz_new_text_device(ctx, sheet, text);
fz_run_page(doc, page, dev, &fz_identity, &cookie);
static fz_rect search_hit_bbox[5000] = {0};
int a = fz_search_text_page(ctx, text, “V1”, search_hit_bbox, 5000);

fz_always(ctx)
        {
            fz_free_device(dev);
            dev = NULL;
            fz_free_text_page(ctx, text);
        }
        fz_catch(ctx)
        {
            fz_drop_display_list(ctx, list);
            fz_free_page(doc, page);
            fz_rethrow(ctx);
        }

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值