haru是一个开源的生成pdf的库,花时间终于编译成功,以下是一个特别简单的写文本的实例:
#include "hpdf.h"
void CDemoDlg::OnBnClickedOk()
{
HPDF_Error_Handler error_handler = NULL;
HPDF_Doc pdf;
pdf = HPDF_New(error_handler, NULL);
if (!pdf)
{
}
HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE);
HPDF_Page page;
page = HPDF_AddPage(pdf);
HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
CString str_Showtxt;
HPDF_Page_BeginText(page);
HPDF_Font font;
HPDF_UseCNSFonts(pdf);
HPDF_UseCNSEncodings(pdf);
font = HPDF_GetFont(pdf, "SimSun", "GB-EUC-H");
HPDF_Page_SetFontAndSize(page, font, 24);
HPDF_Page_MoveTextPos(page, HPDF_Page_GetWidth(page) / 4+60, HPDF_Page_GetHeight(page) - 40);
HPDF_Page_ShowText(page, "xxx检测结果");
HPDF_Page_EndText(page);
HPDF_SaveToFile(pdf, "test.pdf");
HPDF_Free(pdf);
}
生成的结果如下: