#include <iostream>
#include "hpdf.h"
void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_data)
{
std::cerr << "libHaru Error: " << error_no << "\n";
}
int main()
{
HPDF_Doc pdf = HPDF_New(error_handler, NULL);
if (!pdf)
{
std::cerr << "Error: failed to create PDF object.\n";
return 1;
}
if (HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL) != HPDF_OK)
{
std::cerr << "Error: failed to set compression mode.\n";
HPDF_Free(pdf);
return 1;
}
HPDF_Page page = HPDF_AddPage(pdf);
if (!page)
{
std::cerr << "Error: failed to add page.\n";
HPDF_Free(pdf);
return 1;
}
HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
HPDF_Page_BeginText(page);
HPDF_Page_SetFontAndSize(page, HPDF_GetFont(pdf, "Helvetica", NULL), 24);
HPDF_Page_TextOut(page, 50, 700, "Hello, World!");
HPDF_Page_EndText(page);
if (HPDF_SaveToFile(pdf, "output.pdf") != HPDF_OK)
{
std::cerr << "Error: failed to save PDF file.\n";
HPDF_Free(pdf);
return 1;
}
HPDF_Free(pdf);
return 0;
}
评论