我尝试将MuPDF创建的PDF文档写入缓冲区
#include <mupdf/fitz.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
fz_matrix ctm;
ctm = fz_scale(1, 1);
ctm = fz_pre_rotate(ctm, 0);
fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
fz_buffer *output = fz_new_buffer(ctx, 0);
fz_document_writer *wri = fz_new_document_writer_with_buffer(ctx, output, "pdf", NULL);
fz_rect mediabox = {0, 0, 600, 800};
fz_device *begin = fz_begin_page(ctx, wri, mediabox);
fz_rect where = {50, 50, 250, 250};
const char *html = "<h1>Hello World!</h1>";
fz_buffer *buf = fz_new_buffer(ctx, 0);
fz_append_string(ctx, buf, html);
fz_story *story = fz_new_story(ctx, buf, NULL, 12.0, NULL);
int out = fz_place_story(ctx, story, where, &where);
fz_draw_story(ctx, story, begin, ctm);
fz_end_page(ctx, wri);
fz_close_document_writer(ctx, wri);
}
但我在
fz_close_document_writer
处点击了 SIGSEGV。经gdb
检查,问题出在使用fz_append_data
附加PDF数据。
你的例子对我有用,但我改为写入 pdf 文件