pl_fpdf icon indicating copy to clipboard operation
pl_fpdf copied to clipboard

usage of pl_fpdf

Open amoroder opened this issue 11 years ago • 7 comments

Hello,

I am new to pl_fpdf and relatively new to pl/Sql. I would like to create a PDF ( I can start from the examples ) and store the PDF in a tables BLOB file. I don't know ho to do this last part.

Could you please help me to handle this probably simple task

Regards Andrea

amoroder avatar May 28 '14 09:05 amoroder

I wonder if it's a good idea to store your pdf in en blob columns ? It seems you will get some performance issues. I think it is better to store it in filesystem There are some good discussion over this topic here. anyway, take a look at my answer to this post on stackoverflow. hth

Pilooz avatar May 28 '14 10:05 Pilooz

instead of Output() procedure use the below function it will return you the pdf.

procedure helloworld is begin FPDF('P','cm','A4'); openpdf; AddPage(); SetFont('Arial','B',16); Cell(0,1.2,'Hello World',0,1,'C'); insert into test_pdf values (pl_fpdf.outputf ()); end helloworld;

function Outputf(pname varchar2 default null,pdest varchar2 default null) return blob is myName word := pname; myDest word := pdest; v_doc blob; -- finally complete document v_blob blob; v_clob clob; v_in pls_integer; v_out pls_integer; v_lang pls_integer; v_warning pls_integer; v_len pls_integer; begin dbms_lob.createtemporary(v_blob, false, dbms_lob.session); dbms_lob.createtemporary(v_doc, false, dbms_lob.session); -- Output PDF to some destination -- Finish document if necessary if state < 3 then ClosePDF(); end if; myDest := strtoupper(myDest); if(myDest is null) then if(myName is null) then myName := 'doc.pdf'; myDest := 'I'; else myDest := 'D'; end if; end if;

-- restitution du contenu...
  v_len := 1;
  for i in pdfDoc.first..pdfDoc.last loop
     v_clob := to_clob(pdfDoc(i));
     if v_clob is not null then
        v_in := 1;
        v_out := 1;
        v_lang := 0;
        v_warning := 0;
        v_len := dbms_lob.getlength(v_clob);
        dbms_lob.convertToBlob(v_blob, v_clob, v_len,
           v_in, v_out, dbms_lob.default_csid, v_lang, v_warning);
        dbms_lob.append(v_doc, dbms_lob.substr(v_blob, v_len));
     end if;
  end loop;
 -- wpg_docload.download_file(v_doc);
  return(v_doc);

exception when others then error('Outputf : '||sqlerrm); end Outputf;

szamrud avatar Jun 11 '14 19:06 szamrud

Am 11.06.2014 21:22, schrieb szamrud:

instead of Output() procedure use the below function it will return you the pdf.

Thank you very much Andreas

amoroder avatar Jun 16 '14 05:06 amoroder

Hello Pilooz,

I discovered something very strange.

I have a for loop that generates PDF documents. The more PDFs I create, the slower the procedure becomes. The first 10 pdfs are created in 9 seconds, for the pdf from 41 to 50 it runs ( sort of ) more than 67 seconds !

08.08.2014 15:58:03 ( start ) 08.08.2014 15:58:12 08.08.2014 15:58:33 08.08.2014 15:59:07 08.08.2014 15:59:57 08.08.2014 16:01:04 ( End )

If I comment out the PDF part the loop over the 50 records happen ins less than 1 second

08.08.2014 16:04:32 08.08.2014 16:04:32 08.08.2014 16:04:32 08.08.2014 16:04:32 08.08.2014 16:04:32 08.08.2014 16:04:32

Is this a known problem of the fpdf library or is this a problem of the pl/Sql interpreter ?

Do you know a solution ?

Thanks Andreas

amoroder avatar Aug 08 '14 14:08 amoroder

Hello,

as I wrote yesterday the package has performance problems if many pdfs are created. I found the reason and now on our server it creates constantly 5 pdfs per second.

In the declaration part of the body

I added

leer tv32k; -- empty Array

and then I added one line to the initialization procedure

procedure fpdf (orientation varchar2 default 'P', unit varchar2 default 'mm', format varchar2 default 'A4') is myorientation word := orientation; myformat word := format; mymargin margin; begin -- Some checks p_dochecks(); -- Initialization of properties page:=0; n:=2; -- Open the final structure for the PDF document.

-- Andreas: pdfdoc is reset at every new document pdfDoc:=leer;

pdfDoc(1) := null;

Bye Andreas

amoroder avatar Aug 09 '14 03:08 amoroder

Hi Amoroder, I don't see the code you added. Could you please post a pull request, if you changed some code in pl_fpdf ?

Pilooz avatar Aug 11 '14 07:08 Pilooz

Am 11.08.2014 um 09:48 schrieb Pierre-Gilles Levallois:

Hi Amoroder, I don't see the code you added. Could you please post a pull request, if you changed some code in pl_fpdf ?

— Reply to this email directly or view it on GitHub https://github.com/Pilooz/pl_fpdf/issues/1#issuecomment-51750662.

Hello,

I did not change your original code, because I am not the big pl/sql expert and I was sure there is a better way to do it then way I did it.

Now i googled and found this simple solution:oneliner.

In the procedure fpdf

add this line pdfDoc.delete();

before pdfDoc(1) := null;

( I dont'know if this assignment is necessary at all )

More about delete on http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/collection_method.htm

Bye Andreas

amoroder avatar Aug 11 '14 11:08 amoroder