MUPDF的集成
網上一搜一大把的MUPDF集成教程,大致步驟如下:
1.git上下載代碼
2.運行 mupdf -> platform -> ios 文件夾下就可以運行官網的demo
- Build目錄下會生成對應各種架構的靜態庫
4.將該目錄下的.a文件復制到我們的項目當中
5.include目錄整個導入到項目中
注意:官網提供的demo是MRC,若是集成到的項目使用ARC則需要進行混編
6.然年就可以調用了。。。。
具體可以看一下MUPDF集成詳情步驟
我找到一種簡單的集成方法
1.直接在項目中通過cocopod 下載 MuPDF
pod 'MuPDF'
注意:
通過cocopod下載的MuPDF是不全的,有丟失圖片文件
這些圖標都沒有
圖片的設置地址:
圖片的設置地址
你可以自定義圖片
你會發現一個大BUG:無法搜索!!
搜索的關鍵代碼
你需要把這里的代碼修改成上面的代碼!
fz_page *page = fz_load_page(ctx, doc, number);
fz_rect mediabox;
fz_stext_sheet *sheet = fz_new_stext_sheet(ctx);
fz_stext_page *text = fz_new_stext_page(ctx, fz_bound_page(ctx, page, &mediabox));
fz_device *dev = fz_new_stext_device(ctx, sheet, text, NULL);
fz_run_page(ctx, page, dev, &fz_identity, cookie);
fz_close_device(ctx, dev);
fz_drop_device(ctx, dev);
hit_count = fz_search_stext_page(ctx, text, needle, hit_bbox, nelem(hit_bbox));
fz_drop_stext_page(ctx, text);
fz_drop_stext_sheet(ctx, sheet);
fz_drop_page(ctx, page);
return hit_count;
現在的MuPDF就是一個完美的代碼的了!!
MuPDF 在項目中使用!!
- 導入頭文件
導入頭文件
#import "mupdf/MuDocRef.h"
#import "mupdf/MuDocumentController.h"
#include "mupdf/fitz.h"
#include "mupdf/common.h"
- 限制文件大小
文件大小
enum
{
ResourceCacheMaxSize = 128<<20 /**< use at most 128M for resource cache */
};
- 關鍵代碼
關鍵代碼
queue = dispatch_queue_create("com.artifex.mupdf.queue", NULL);
screenScale = [[UIScreen mainScreen] scale];
ctx = fz_new_context(NULL, NULL, ResourceCacheMaxSize);
fz_register_document_handlers(ctx);
NSString *file = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"pdf"];
MuDocRef *doc;
doc = [[MuDocRef alloc] initWithFilename:file];
if (!doc) {
NSLog(@"Cannot open document '%@'", file);
return YES;
}
MuDocumentController *document = [[MuDocumentController alloc] initWithFilename:file path:file document: doc];
這樣就可以了,打開PDF的時候帶著文件名跳轉到這個控制器就可以了!
大功告成!!
這是缺失圖片: