Announcement

Collapse
No announcement yet.

Help with hpdf

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with hpdf

    Hi.


    I am using libHaru in a Lua Script (AutoPlay Media Studio). Everything is ok BUT I cannot use the command HPDF_Page_TextRect().

    Ex:

    require "hpdf"
    local pdf = hpdf.New()

    if pdf then
    local page = hpdf.AddPage(pdf)
    hpdf.Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT)

    local height = hpdf.Page_GetHeight(page)
    local width = hpdf.Page_GetWidth(page)

    --Cabeçalho
    local image = hpdf.LoadPngImageFromFile(pdf,"esquerda.png")
    local image2 = hpdf.LoadPngImageFromFile(pdf,"direita.png")
    hpdf.Page_DrawImage(page,image, 30, height - 100, 138, 50.5)
    hpdf.Page_DrawImage(page,image2, width-30-140.5, height - 100, 140.5, 50,5)

    --Identificação
    local font = hpdf.GetFont(pdf, "Times-Bold", "WinAnsiEncoding")
    hpdf.Page_SetFontAndSize(page, font, 12)
    hpdf.Page_BeginText(page)
    hpdf.Page_TextOut(page, 30, height - 250, "Processo:")

    hpdf.Page_TextOut(page, 30, height - 275, "Interessado:")
    hpdf.Page_EndText(page)


    This works very well. Now, I will try to add a long text in a rectangle and justify it.


    local ementa = "Esse é um texto muito específico e longo. Sua função é testar a funcionalidade de colocação de um texto justificado dentro de um determindo espaço de página. Vamos ver se funciona. Parece bom!";
    hpdf.Page_TextRect(page,0,0,200,200,ementa,HPDF_TA LIGN_JUSTIFY,);

    hpdf.Page_TextRect does not work. The IDE says that the 7th argument must be 'string'. This is a string. I tryed to change the place of arguments to hpdf.Page_TextRect(page,0,0,200,200,ementa,HPDF_TA LIGN_JUSTIFY,);

    In this case the problem is in the 7th argument.



    I think about compile libhpdf to the last version (2.3) but I gave up, I don't know how.

    Any help?

    Thsnks


  • #2
    HPDF_TA LIGN_JUSTIFY might not be set you might have to set these yourself also you added another commor after HPDF_TA LIGN_JUSTIFY

    hpdf.Page_TextRect(page,0,0,200,200,ementa,HPDF_TA LIGN_JUSTIFY,);


    Find out what HPDF_TA LIGN_JUSTIFY is meant to say or equal and add it manually "WHATEVERITIS" rather then the HPDF_TA LIGN_JUSTIFY or before define HPDF_TA LIGN_JUSTIFY = "WhatEverITsMeantToBe";

    also if local ementa = is multi line then do

    local ementa = [[Esse é um texto muito específico e longo. Sua função é testar a funcionalidade de colocação de um texto justificado dentro de um determindo espaço de página. Vamos ver se funciona. Parece bom!]];
    if its not multi lined then you can get ways with

    local ementa =Esse é um texto muito específico e longo. Sua função é testar a funcionalidade de colocação de um texto justificado dentro de um determindo espaço de página. Vamos ver se funciona. Parece bom!";

    Better if you explore the APZ, file and export so we can look at your app to see what could be going wrong.
    Plugins or Sources MokoX
    BunnyHop Here

    Comment


    • #3
      Hi kingzooly

      I am sending the APZ. Thank you for your help. This is very important.

      Thanks
      Attached Files

      Comment


      • #4
        This is not an error in the LuaPDF or the libHaru library I provided, and you are using, but there are several problems in your code.

        Before you can output text in Haru, you need to activate the Text mode. This is done with
        Code:
        hpdf.Page_BeginText(page);
        This command must be executed before the first call to text output, such as hpdf.Page_TextRect(), hpdf.Page_TextOut() and so on.

        Then you have three problems with your call to hpdf.Page_TextRect():

        First, you inverted the order of the arguments in the attached APZ, where you wrote this:
        Code:
         hpdf.Page_TextRect(page,0,0,200,200, HPDF_TALIGN_JUSTIFY,ementa);
        The proper code is:
        Code:
        hpdf.Page_TextRect(page, 0, 792, 200, 200, ementa, "HPDF_TALIGN_JUSTIFY");
        Note the proper order of the arguments. Second, the last argument is a string, which means that it requires quotes (this is how the library was written, not my choice). The third mistake is that instead of using 0,0 as the origin of the text you need to use 0,792. If you use 0,0 you are printing outside of the page - this is the LOWER left corner of the page. The UPPER left corner is 0,792 for an A4 page.

        You can find a corrected version of your project attached.

        Ulrich
        Attached Files

        Comment


        • #5
          Hi Ulrich

          I just can say YOU ARE THE BEST.

          You saved me.

          Ttank you!

          Comment

          Working...
          X