I have following and getting very long line which want to convert into multiple line. As of now, The text is going outside my pdf.
int show_data(){
YPOS -= 10;
NextPage();
double ypos = YPOS;
double maxWidth = HPDF_Page_GetWidth(currentpage) - (m_Margin * 2);
double indentStart = 2 * m_Margin;
double xpos = indentStart;
bool thereIsText = (text.length() > 0);
int textPos = 0;
string newText;
while (thereIsText) {
// maxWidth-xpos is the max length of text allowed per line;
newText = text.substr(textPos);
HPDF_TextWidth spacewidth =
HPDF_Font_TextWidth(font, (const HPDF_BYTE *) " ", 1);
HPDF_TextWidth tw =
HPDF_Font_TextWidth(font, (const HPDF_BYTE *) newText.c_str(),
newText.length());
textPos += (newText.length() + 1);
HPDF_Page_BeginText(currentpage);
loginfo<<xpos<<ypos<<endl;
HPDF_Page_SetFontAndSize (currentpage, font, 24);
HPDF_Page_SetLineWidth(currentpage, 80);
HPDF_Page_MoveTextPos(currentpage,-220, ypos);
//HPDF_Page_MoveToNextLine
//HPDF_Page_TextOut(currentpage,xpos,ypos, newText.c_str());
//HPDF_Page_MoveTo(currentpage, 120, 195);
//HPDF_Page_MoveTextPos (currentpage, 20, 20);
HPDF_Page_ShowTextNextLine(currentpage, newText.c_str());
HPDF_Page_EndText(currentpage);
if ((unsigned int) textPos >= text.length())
thereIsText = false;
ypos -= 10;
loginfo<<" ypos ... "<<ypos<<endl;
loginfo<< " m_Margin.... "<<m_Margin<<endl;
/*if (ypos <= m_Margin) {
NextPage();
ypos = HPDF_Page_GetHeight(currentpage) - m_Margin;
}*/
xpos = m_Margin;
}
YPOS = ypos;
}
Well, assuming that my comment/question to the OP was anywhere near relevant, I understood the question to be how to insert very long lines into a libharu-generated PDF document without exceeding print boundaries.
Libharu supports text boxes (HPDF_Page_TextRect()) which create a boundary for the text written to them. It word-wraps (in the layman's definition of the term) on full words (ie, no '...' or '-'s inserted) and does the job pretty well. All you need to do is define the size of the HPDF_Rect you're going to use. Of course, this means you can end up getting the size of the box too small to fit all the text, so you have to still be fairly careful about setting things up.
From the Libharu site (https://github.com/libharu/libharu/wiki/API%3A-Graphics#wiki-HPDF_Page_TextRect) you can find the format of HPDF_Page_TextRect, but basically you give it dimensions, text to display and a couple of formatting/behavioural parameters.
You've probably already answered this yourself, by now.