This discussion is archived
1 2 Previous Next 27 Replies Latest reply: Jun 4, 2012 8:28 AM by brian.mcginity RSS

Does anyone uses PL_FPDF?

milk Newbie
Currently Being Moderated
I need help.
I want to print a simple spreadsheet of employees.
The problem is if the text is longer than the cell,
passes over the following cell and doesn't go in a new row of the same cell.

This is an example.

Thanks!

begin
pl_fpdf.FPDF('P','mm','A4');
pl_fpdf.openpdf;
pl_fpdf.setdisplaymode ('fullpage', 'single');
pl_fpdf.AddPage();
pl_fpdf.SetFont('Arial','',9);

pl_fpdf.cell(15,7,'ID','B');
pl_fpdf.cell(60,7,'Name','B');
pl_fpdf.cell(30,7,'Lastnmae','B',1);
for c in (select id,name,lastname from emp order by lastname) loop
pl_fpdf.Cell(15,5,c.id);
pl_fpdf.Cell(30,5,c.name);
pl_fpdf.Cell(30,5,c.lastname,null, 1);
end loop;
pl_fpdf.Output(Emp.pdf','I');
end;
  • 1. Re: Does anyone uses PL_FPDF?
    milk Newbie
    Currently Being Moderated
    Anyone?
  • 2. Re: Does anyone uses PL_FPDF?
    mobra Journeyer
    Currently Being Moderated
    The problem is if the text is longer than the cell,
    passes over the following cell and doesn't go in a new row of the same cell.
    There is a method (function) that allows you to compute the width of a string, allowing you to adjust the width of the cell as required:

    http://www.fpdf.org/en/doc/getstringwidth.htm

    Also take a look at the rest of the documentation (it's for PHP, but the PL/SQL version uses the same API, more or less):

    http://www.fpdf.org/



    - Morten

    http://ora-00001.blogspot.com
  • 3. Re: Does anyone uses PL_FPDF?
    milk Newbie
    Currently Being Moderated
    Thanks for your reply.
    I've tried some but without success.
    Do you have an example.
  • 4. Re: Does anyone uses PL_FPDF?
    mobra Journeyer
    Currently Being Moderated
    I've tried some but without success.
    Do you have an example.
    Show me your code first.

    - Morten

    http://ora-00001.blogspot.com
  • 5. Re: Does anyone uses PL_FPDF?
    milk Newbie
    Currently Being Moderated
    This is my code.
    Almost works well.
    This [http://qualitypoint.blogspot.com/2010/07/resolved-wrap-text-issue-in-fpdf-table.html] has helped me.


    create or replace
    PROCEDURE PDF_EMP AS
    v_y0 number;
    v_y1 number;
    v_H number;
    v_x number;
    v_x0 number;
    v_row number;
    v_len number;
    v_pg number;
    v_name varchar2(60);
    BEGIN
    pl_fpdf.FPDF('P','mm','A4');
    pl_fpdf.openpdf;
    pl_fpdf.setdisplaymode ('fullpage', 'single');
    pl_fpdf.AddPage();
    pl_fpdf.SetFont('Arial','',9);

    pl_fpdf.cell(15,7,'ID','B');
    pl_fpdf.cell(1,7,' ');
    pl_fpdf.cell(60,7,'Name','B');
    pl_fpdf.cell(1,7,' ');
    pl_fpdf.cell(30,7,'E-mail','B',1);
    v_y0:=pl_fpdf.gety();
    v_y1:=v_y0;
    v_x:=pl_fpdf.getx();
    v_x0:=pl_fpdf.getx();
    v_H:=5;
    v_row:=1;
    v_len:=1;
    for c in (select id,lastname,eml from emp order by lastname) loop

    -- What would be the height row-----------------------------
    if pl_fpdf.GetStringWidth(c.id) >= 15 then
    if pl_fpdf.GetStringWidth(c.id)/15 > 1 then
    v_len:=ceil(pl_fpdf.GetStringWidth(c.id)/15);
    end if;
    end if;

    v_name:=replace(c.lastname,' ',chr(0));

    if pl_fpdf.GetStringWidth(v_name) >= 58 then
    if pl_fpdf.GetStringWidth(v_name)/58 > 1 then
    v_len:=ceil(pl_fpdf.GetStringWidth(v_name)/58);
    end if;
    end if;
    v_H:=v_len*v_H;
    -- New page----------------------------------------------
    if (v_y1+v_H) >= pl_fpdf.getH then
    pl_fpdf.AddPage();
    pl_fpdf.cell(15,7,'ID','B');
    pl_fpdf.cell(1,7,' ');
    pl_fpdf.cell(60,7,'Name','B');
    pl_fpdf.cell(1,7,' ');
    pl_fpdf.cell(30,7,'E-mail','B',1);
    v_y0:=pl_fpdf.gety();
    v_y1:=v_y0;
    end if;

    COL1 ----------------------------------------------------

    pl_fpdf.setxy(v_x,v_y1);
    pl_fpdf.cell(v_x+15,v_H,'','B',null,null);
    pl_fpdf.setxy(v_x,v_y1);
    pl_fpdf.MultiCell(15,6,c.id);

    COL2 ----------------------------------------------------

    pl_fpdf.setxy(v_x+15,v_y1);
    pl_fpdf.cell(60,v_H,'','B');
    pl_fpdf.setxy(v_x+15,v_y1);
    pl_fpdf.MultiCell(60,5,v_name,null,'L');
    COL3 ----------------------------------------------------
    v_x:=v_x+15;
    pl_fpdf.setxy(v_x+60,v_y1);
    pl_fpdf.cell(30,v_H,'','B',1,null);
    pl_fpdf.setxy(v_x+60,v_y1);
    pl_fpdf.MultiCell(30,5,c.eml);
    --------------------------------------------------------------
    v_x:=v_x0;
    v_len:=1;
    v_y1:=v_y1+v_H;
    v_row:=v_row+1;
    v_H:=5;
    end loop;
    pl_fpdf.Output('emp.pdf','I');
    END PDF_EMP;
  • 6. Re: Does anyone uses PL_FPDF?
    654291 Newbie
    Currently Being Moderated
    I'm having trouble getting the AddLink() function to work.
    v_link_id :=pl_fpdf.AddLink();
    Is returning an error of
    ORA-06531: Reference to uninitialized collection
    I have confirmed that this is the call causing the issue, by removing and proving that the PDF is created.

    Is anyone out there using the AddLink() function successfully?
  • 7. Re: Does anyone uses PL_FPDF?
    654291 Newbie
    Currently Being Moderated
    Okay, I have uodated the function definition and I'm getting further. Here is the updated definition
    function AddLink return number is
    nb_link number;
    begin
    if links is null
    then
    links := Array2dim();
    end if;
    links.extend;
    nb_link := links.count;
      -- Create a new internal link
         links(nb_link).zero := 0;
         links(nb_link).un := 0;
      return nb_link;
    end AddLink;
    This seems to work.

    Next problem is when I add a cell or write and add the plink parameter. No error is produced, but the the PDF is invalid. The PDF is valid if I use an external link (i.e. a URL). Oh well, onwards and upwards.

    I'll have to dive into the package and how a PDF works to figure this one out I suspect. Definately a job for next week!.
  • 8. Re: Does anyone uses PL_FPDF?
    654291 Newbie
    Currently Being Moderated
    Update on my adventures with the Internal Links.

    External links work. i.e. www.google.com.
    Internal links don't. The code that puts them on the PDF page is commented out the procedure is p_putpages.

    Also, looking at the code, only one link per page is currently allowed.

    If I have the time and courage, I'm going to take a look at the code that handles this and see if I can fix/re-write it.
  • 9. Re: Does anyone uses PL_FPDF?
    843386 Newbie
    Currently Being Moderated
    Did you ever fix the overlap issue? I'm currently trying to use PL_FPDF to output what I thought would be a simple PDF file... The page was supposed to have multiple columns a rows, but the content of any and or all overlaps other cells / writes due to how everything is placed on the page as well as the dynamic nature of the data that comes in from the database (i.e. - one cell or area might only have 2 items to output while another might wind up having 8 or 10... Hence, the overlap.)
  • 10. Re: Does anyone uses PL_FPDF?
    654291 Newbie
    Currently Being Moderated
    Just finished fixing the links.

    You can now have more than one link on a page and you can use links internal to the document as well as URL's.

    If anyone wants a copy of the updated package, let me know.
  • 11. Re: Does anyone uses PL_FPDF?
    mobra Journeyer
    Currently Being Moderated
    Just finished fixing the links.

    You can now have more than one link on a page and you can use links internal to the document as well as URL's.

    If anyone wants a copy of the updated package, let me know.
    I'm interested. Can you put the modified file anywhere for download?

    Alternatively, you could paste your code changes into the Comments on my blog post about PL_FPDF:

    http://ora-00001.blogspot.com/2009/10/free-pdf-package-for-plsql.html

    Note: I didn't write PL_FPDF (Pierre-Gilles Levallois did), but I have written a few fixes of my own for the package, including using clobs to avoid the 32K limit. Perhaps I should include the improved version in the Alexandria Library for PL/SQL (so far I've avoided this when there is another "official" source for a package, but it doesn't seem like Levallois has updated the package in a while), in which case it would be good to include your fixes for the links as well:

    http://code.google.com/p/plsql-utils/



    - Morten

    http://ora-00001.blogspot.com

    Edited by: mobra on May 25, 2011 8:29 PM
  • 12. Re: Does anyone uses PL_FPDF?
    654291 Newbie
    Currently Being Moderated
    Morten,
    I've had to change several of the functions and procedures to make it all come together. So I'm not sure posting the changes into the comments of the blog will work.

    If you want the package I can give it to you and you can compare it to the standard to see what I changed. That would make it easier to update yours.
  • 13. Re: Does anyone uses PL_FPDF?
    brian.mcginity Newbie
    Currently Being Moderated
    I am also working with pl_fpdf. If anyone else is testing this, one word of caution.

    There is a function p_dochecks which does:
    execute immediate 'alter session set NLS_NUMERIC_CHARACTERS = '',.'''

    In a web environment with pooling, this caused other sessions to randomly throw Character to Numeric conversion errors. The solution is to comment this line.

    I’ve also altered the package to make it work with clobs and javascript. Seems to be working. It would be nice to collaborate with others as I’m sure we’re all pretty much fixing the same problems.
  • 14. Re: Does anyone uses PL_FPDF?
    mobra Journeyer
    Currently Being Moderated
    Dramus wrote:
    Morten,
    I've had to change several of the functions and procedures to make it all come together. So I'm not sure posting the changes into the comments of the blog will work.

    If you want the package I can give it to you and you can compare it to the standard to see what I changed. That would make it easier to update yours.
    Yes, let's collaborate on this, and make it part of the Alexandria Library for PL/SQL.

    You can go to the Issues page, create a new issue, and add your code as an attachment to the issue:

    http://code.google.com/p/plsql-utils/issues/list



    - Morten

    http://ora-00001.blogspot.com
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points