【问题标题】:Cannot write texts in a PDF file using libHaru无法使用 libHaru 在 PDF 文件中写入文本
【发布时间】:2015-04-12 16:31:08
【问题描述】:

以下代码创建一个包含两个单词的 PDF 文件并保存:

#include "hpdf.h"
#include <iostream>

void error_handler (HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data) {
    std::cerr << "error! " << error_no << " " << detail_no << '\n';
    throw std::exception();
}

int main() {
    HPDF_Doc pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        std::cerr << "Error: Cannot create pdf object" << '\n';
        return 1;
    }
    try {
        HPDF_Page page = HPDF_AddPage(pdf);
        HPDF_Page_BeginText (page);
        HPDF_Page_TextOut (page, 0,0,"sample text");
        HPDF_Page_EndText(page);
        HPDF_SaveToFile (pdf, "test.pdf");
        std::cout << "file save: " << '\n';
    } catch (const std::exception& e) {
        e.what();
        HPDF_Free(pdf);
        return 1;
    }
    HPDF_Free(pdf);
}

当这一行时:

HPDF_Page_TextOut (page, 0,0,"sample text");

被执行,我得到:

error! 4174 0

我在 libHaru 文档中找不到任何关于错误代码 4174 的信息,谁能解释一下这是什么意思?

【问题讨论】:

    标签: c++ pdf libharu


    【解决方案1】:

    您的错误处理程序以十进制输出错误代码,而文档将它们列为十六进制。

    4174(十进制)等于 0x104e(十六进制)。

    此错误代码在 libharu 文档中列为 HPDF_PAGE_FONT_NOT_FOUND

    请参阅有关如何解决此问题的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      相关资源
      最近更新 更多