在Windows 8.1上使用MuPDF创建pdf的图像注释

Create image annotation of pdf using MuPDF on Windows 8.1

本文关键字:pdf 创建 图像 注释 MuPDF Windows      更新时间:2023-10-16

我正在C++上开发一个WinRT应用程序,它应该可以帮助用户阅读和注释PDF文件。我正在使用MuPDF来解析PDF。我可以阅读PDF并添加行和自由文本注释,但无法在页面中插入图像。我找不到任何样品,也找不到解释我要找什么的手册。我正在使用以下代码创建图像,但图像没有出现:

std::string pathToOutputBook3 += "\testPDF.pdf";
std::string pathToImage3 = "Assets/hortitsa.jpg";
fz_point pts[4] = { { 0, 0 }, { 0, 0 }, { 600, 0 }, { 600, 499 } };
fz_rect rect = fz_empty_rect;
pdf_document *pdfDoc = (pdf_document *)this->mu_doc;
pdf_page *pdfPage = (pdf_page *)page;
image_document *imgDoc = (image_document *)fz_open_document(this->mu_ctx, pathToImage3.c_str());
fz_image *image = imgDoc->image;
fz_matrix page_ctm = { 1, 0, 0, 1, 0, 0 };
fz_include_point_in_rect(&rect, &pts[0]);
fz_include_point_in_rect(&rect, &pts[1]);
fz_include_point_in_rect(&rect, &pts[2]);
fz_include_point_in_rect(&rect, &pts[3]);
display_list = fz_new_display_list(this->mu_ctx);
dev = fz_new_list_device(this->mu_ctx, display_list);
auto annot = pdf_create_annot(pdfDoc, pdfPage, fz_annot_type::FZ_ANNOT_SQUARE);
fz_fill_image(dev, image, &page_ctm, 1.0f);
fz_transform_rect(&rect, &page_ctm);
pdf_set_annot_appearance(pdfDoc, annot, &rect, display_list);
fz_write_document(this->mu_doc, (char *)pathToOutputBook3.c_str(), nullptr);

没有"image"注释类型。有些注释类型可能被滥用以在外观中存储图像,但忽略外观流并从注释字典(如Adobe Acrobat)创建新的注释流的读者仍然不会显示图像。

如果你想在文档中添加图像,那么你需要这样做,而不是尝试使用注释。我相信现在可以使用MuPDF将图像添加到页面内容流中,但我自己不知道如何做到这一点。