在 MuPDF C API 中写入 PDF 到缓冲区

问题描述 投票:0回答:1

我尝试将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数据。

c mupdf
1个回答
0
投票

你的例子对我有用,但我改为写入 pdf 文件

© www.soinside.com 2019 - 2024. All rights reserved.