1

I am working on a project in which i have to convert documents into pdf files programmatically in c++. I am using libharu open source library for this. My code is working good if the document is of one single page but when i am changing page the pdf document corrupts and it does not opens. Can any one suggest solution for this.

while(chars_traversed < text.size())
{
    chars_copied = HPDF_Page_MeasureText(pd->track->page , (text.c_str() + chars_traversed) , pw , false , NULL);
    memset(buffer , 0 , sizeof(buffer));
    text.copy(buffer , chars_copied , chars_traversed);

    HPDF_Page_MoveToNextLine(pd->track->page);
    HPDF_Page_ShowText (pd->track->page, buffer);

    chars_traversed += chars_copied;

    arr = HPDF_Page_GetCurrentTextPos(pd->track->page);

    if(arr.y < end_y)
    {
                    /* Page change required */
        HPDF_Page_EndText(pd->track->page);
        insert_page_at_last(pd);
        HPDF_Page_MoveTextPos(pd->track->page , start_x , start_y);
         }
}
GDSM
  • 166
  • 2
  • 7

2 Answers2

2

Once you reach the bottom of the page and want to start another page you need to

  HPDF_Page_EndText (hPage)
  hPage = HPDF_AddPage (pdf)
  HPDF_Page_BeginText (hPage)
  HPDF_Page_MoveTextPos (hPage, LeftMargin, nHeight - TopMargin)

This syntax is for Powerbasic but I assume you get the idea.

0

Refer this LIB Haru source code.

It describehow to convert documents into pdf files very well.

This API also usefull to you.

Hope this will help you.

AB Bolim
  • 1,997
  • 2
  • 23
  • 47