15 const HPDF_STATUS detail_no,
24 const HPDF_REAL line_height,
const HPDF_REAL max_lines = NULL) {
26 std::string current_text = text;
27 size_t total_lines = 0;
29 while (!current_text.empty()) {
30 const HPDF_UINT len = HPDF_Page_MeasureText(page, current_text.c_str(), max_width, HPDF_TRUE, &real_width);
35 current_text = current_text.substr(len);
36 if (max_lines != NULL and total_lines == max_lines) {
41 return total_lines * line_height;
46inline HPDF_REAL
writeText(
const HPDF_Page page, std::string text,
const HPDF_REAL left,
47 const HPDF_REAL top,
const HPDF_REAL line_height,
const HPDF_REAL max_width,
const _HPDF_TextAlignment alignment,
const HPDF_REAL max_height) {
49 const HPDF_REAL bottom = (max_height == NULL) ? NULL : (top - max_height);
55 HPDF_Page_BeginText(page);
56 HPDF_Page_TextRect(page, left, top, left + max_width, bottom, text.c_str(), alignment,
58 HPDF_Page_EndText(page);
65 const HPDF_REAL top,
const HPDF_REAL line_height,
const HPDF_REAL max_width,
const _HPDF_TextAlignment alignment,
const HPDF_REAL max_height) {
67 const HPDF_REAL bottom = (max_height == NULL) ? NULL : (top - max_height);
73 if (textHeight > max_height) {
77 HPDF_Page_BeginText(page);
78 HPDF_Page_TextRect(page, left, top, left + max_width, bottom, text.c_str(), alignment,
80 HPDF_Page_EndText(page);
86inline HPDF_REAL
writeText(
const HPDF_Page page, std::string text,
const HPDF_REAL left,
87 const HPDF_REAL top,
const HPDF_REAL line_height,
const HPDF_REAL max_width,
const _HPDF_TextAlignment alignment,
const int max_lines = 0) {
89 const HPDF_REAL bottom = (max_lines == NULL) ? NULL : (top - max_lines * line_height);
95 HPDF_Page_BeginText(page);
96 HPDF_Page_TextRect(page, left, top, left + max_width, bottom, text.c_str(), alignment,
98 HPDF_Page_EndText(page);
105 const HPDF_REAL top,
const HPDF_REAL line_height,
const HPDF_REAL max_width,
const _HPDF_TextAlignment alignment,
const int max_lines = 0) {
107 const HPDF_REAL bottom = (max_lines == NULL) ? NULL : (top - max_lines * line_height);
112 std::cout << textHeight <<
" " << max_lines * line_height << std::endl;
113 if (textHeight > max_lines * line_height) {
116 HPDF_Page_BeginText(page);
117 HPDF_Page_TextRect(page, left, top, left + max_width, bottom, text.c_str(), alignment,
119 HPDF_Page_EndText(page);
125inline HPDF_REAL
changeFont(
const HPDF_Page page,
const HPDF_REAL font_size,
const HPDF_Font font) {
126 const float line_height = font_size * 1.2;
127 HPDF_Page_SetFontAndSize(page, font, font_size);
128 HPDF_Page_SetTextLeading(page, line_height);
133inline void drawLine(
const HPDF_Page page,
const HPDF_REAL from_x,
const HPDF_REAL from_y,
const HPDF_REAL to_x,
const HPDF_REAL to_y) {
134 HPDF_Page_MoveTo(page, from_x, from_y);
135 HPDF_Page_LineTo(page, to_x, to_y);
136 HPDF_Page_Stroke(page);
Libharu Exception.
Definition pdf_exception.h:7
void error_handler(const HPDF_STATUS error_no, const HPDF_STATUS detail_no, void *user_data)
libharu error handler
Definition pdf_utils.h:14
HPDF_REAL calculate_text_height(const HPDF_Page page, const std::string &text, const HPDF_REAL max_width, const HPDF_REAL line_height, const HPDF_REAL max_lines=NULL)
calculates the height of a given text on the pdf
Definition pdf_utils.h:23
HPDF_REAL writeTextIfNotLinesExceeded(const HPDF_Page page, std::string text, const HPDF_REAL left, const HPDF_REAL top, const HPDF_REAL line_height, const HPDF_REAL max_width, const _HPDF_TextAlignment alignment, const int max_lines=0)
write text on to the pdf at a given point when max lines is not exceeded
Definition pdf_utils.h:104
HPDF_REAL writeText(const HPDF_Page page, std::string text, const HPDF_REAL left, const HPDF_REAL top, const HPDF_REAL line_height, const HPDF_REAL max_width, const _HPDF_TextAlignment alignment, const HPDF_REAL max_height)
write text on to the pdf at a given point
Definition pdf_utils.h:46
HPDF_REAL writeTextIfNotHeightExceeded(const HPDF_Page page, std::string text, const HPDF_REAL left, const HPDF_REAL top, const HPDF_REAL line_height, const HPDF_REAL max_width, const _HPDF_TextAlignment alignment, const HPDF_REAL max_height)
write text on to the pdf at a given point when max height is not exceeded
Definition pdf_utils.h:64
HPDF_REAL changeFont(const HPDF_Page page, const HPDF_REAL font_size, const HPDF_Font font)
change the font and font size
Definition pdf_utils.h:125
void drawLine(const HPDF_Page page, const HPDF_REAL from_x, const HPDF_REAL from_y, const HPDF_REAL to_x, const HPDF_REAL to_y)
draw a line, line width needs to be set before
Definition pdf_utils.h:133
std::string UTF8toISO8859_1(const std::string &utf8_str)
converts a UTF8 string to ISO8859-1 / ANSI using iconv
Definition utils.h:11