hpdf_doc::hpdf_doc(const char* filepath) { h_pdf = HPDF_New(error_handler, NULL); HPDF_UseCNTFonts(h_pdf); HPDF_UseCNTEncodings(h_pdf); // set CHT fonts and encoding HPDF_UseUTFEncodings(h_pdf); strcpy(filename, filepath); f_page_width = def_f_width; f_page_length = def_f_length; f_margin_top = def_f_margin_top; f_margin_left = def_f_margin_left; f_margin_bottom = def_f_margin_bottom; f_margin_right = def_f_margin_right; h_direction = HPDF_PAGE_PORTRAIT; }
void FileCreator(const std::string path, const std::string destFileName, const std::string outline ) { std::vector<std::string> files = util::listDir(path); if (files.size() <= 0)return; std::sort(std::begin(files), std::end(files)); /////////////////////////// HPDF_Doc pdf; pdf = HPDF_New(error_handler, NULL); if (!pdf) { std::cout<<"error: cannot create PdfDoc object"<<std::endl; return; } if (setjmp(env)) { HPDF_Free(pdf); return; } /* const char *font_name1; const char *font_name2; const char *font_name3; font_name1 = HPDF_LoadTTFontFromFile(pdf, "C:\\Windows\\Fonts\\Arial.ttf", HPDF_TRUE); font_name2 = HPDF_LoadTTFontFromFile(pdf, R"(C:\Windows\Fonts\simsunb.ttf)", HPDF_TRUE); font_name3 = HPDF_LoadTTFontFromFile2(pdf, "C:\\Windows\\Fonts\\simsun.ttc", 1, HPDF_TRUE); */ HPDF_Outline root; root = HPDF_CreateOutline(pdf, NULL, outline.c_str(), NULL); HPDF_Outline_SetOpened(root, HPDF_TRUE); HPDF_SetInfoAttr(pdf, HPDF_INFO_AUTHOR, config::AUTHOR); HPDF_SetInfoAttr(pdf, HPDF_INFO_TITLE, path.c_str()); HPDF_Font font; switch (config::LANG_TYPE) { case pdf::config::CN: HPDF_UseCNSFonts(pdf); HPDF_UseCNSEncodings(pdf); font = HPDF_GetFont(pdf, "SimHei", "GB-EUC-H"); // SimSun SimHei break; case pdf::config::TW: HPDF_UseCNTFonts(pdf); HPDF_UseCNTEncodings(pdf); font = HPDF_GetFont(pdf, "MingLiU", "ETen-B5-H"); break; default: font = HPDF_GetFont(pdf, "Helvetica", NULL); break; } /////////////////////////// std::string contents; std::vector<std::string> vec; for (std::string file : files) { contents = util::getFileContents(file); vec = util::split(contents, '\n'); fileWriter(pdf, root, font, file.substr(path.length()), vec); } /////////////////////////// std::string destFile(path); destFile.append("/"); destFile.append(destFileName); HPDF_SaveToFile(pdf, destFile.c_str()); HPDF_Free(pdf); }//end FileCreator()