Home > [old] Information > Archives > Technologies > Archives > PL/SQL > PL_FPDF
PL_FPDF
Free PL/SQL library to generate PDF from Oracle Database
Monday 7 July 2008
All the versions of this article: [English] [français]
The free PL/SQL library to generate PDF are very hard to find.
As I could not find one, I’ve written it from the well known PHP library FPDF which was written by Olivier Plathey.
I propose you the last release of the PL_FPDF library (0.9.3).
I already use it on our production site laclasse.com.
This code gives you the same functions than FPDF, except that it converts all the images you need in PNG.
Required Environment
– Oracle en version 10g (10.2.0.1 and above).
– Installation ofOracle Web Tool Kit required (owa, htp and htf packages).
– OrdSys.OrdImage required (Oracle cartridge for images).
– Installation of package URIFactory required.
Changelog
– 0.9.2 -> 0.9.3 :
- Added Sample on setHeaderProc and setFooterProc procedures.
- Added parameter implementation to thes procedures.
- Modify Header and footer procedure behaviour to get parameter values
- declared subtype ’word’ ans type ’tv4000a’ in the specs.
– 0.9.1 -> 0.9.2 :
- Added procedure helloword Example.
- Added procedure testImg Example.
– 0.9.1 First Stable Version !
- Minor bugs (thanks to Josh Burroughs)
- Corrections on p_parseimage procedure (better reading of image files)
- Corrections on p_escape procedure
– 0.9-Beta2
- Minor bugs (thanks to Rudy Winter)
- Corrections on Image procedure
- Corrections on header and Footer procedures
- Multiple images on the same page works, but only with png Format.
Known bugs on this version
– GIF images are not supported, because of a PNG conversion problem.
– No PDF file compression. (This not a bug but a lack of feature).
– Write procedure which allows to put a flow of text dealing with the page height and width, don’t run as well.
– ...
Asked Features
– Dynamique SQL execution procedure that generates aPDF table.
Download, Test, and code !
I’m very interessted in having back your codes, bugs corrections and evolutions.
code examples
Here are some online examples :
Here are some simple code samples with PL_FPDF.
helloWord
Note that the "output" procedure calls automatically "ClosePdf".
procedure helloworld is
begin
pdf.FPDF('P','cm','A4');
pdf.openpdf;
pdf.AddPage();
pdf.SetFont('Arial','B',16);
pdf.Cell(0,1.2,'Hello World',0,1,'C');
pdf.Output();
end helloworld;Put an image
procedure testImg is
img varchar2(2000);
begin
pdf.FPDF('P','cm','A4');
pdf.openpdf;
pdf.AddPage();
pdf.SetFont('Arial','B',16);
img := 'http://www.laclasse.com/v2/images/picto_laclassev2.png';
pdf.Image(img,1, 1, 10);
pdf.Output();
end testImg;Any message or comments?
You must be registered before participating in this forum. Please enter your personal identifier . If you have not yet registered, you must register.
back.projets.erasme.org
Forum posts
1. PL_FPDF, 11 August 2008, 03:22, by kishor
Great work.
I dont know if its limitation or I am having problems. Like can not put image, document size limit to 32k etc. i.e not usable for bigger complex/reports.
Do you have any updated version?
Regards
Kishor
1. PL_FPDF, 11 August 2008, 10:06, by Pierre-Gilles Levallois
I think this is a limitation due to a PlSQL variable that is no more longer than 32K, I have to chck the types of the record cotaining the images.
no update planned for august, I think I will work on it in September/October ?
Best regards.
2. PL_FPDF, 14 August 2008, 10:39, by Pierre-Gilles Levallois
Hi,
I had a look about the problem. I confirm than you can put big images in pdf (more than 32K).
see example below.
Perhaps you have problem in the configuration ? in the requiered environnement ?
Let me now which error message you get...
3. PL_FPDF, 15 September 2008, 06:40, by kishor
Hi,
Thanks for your reponse.
Without any images, it creates the PDF and is displayed fine.
However I am still getting the same error when I try to display an image.
ie HTTP-404 The webpage can not be found.
When I do the following from explorer
http://myserver/i/reddot.gif
the image is displayed.
But with
pl_fpdf.Image(’http://myserver/i/reddot.gif’ ,1, 1, 10);
the page gives "The webpage can not be displayed".
Is there any configuration changes required?
have also tried
pl_fpdf.Image(’http://www.laclasse.com/v2/images/b2i/fonds/fd_livret_college.png’ ,1, 1, 10);
Appreciate your advise.
Kishor
4. PL_FPDF, 17 September 2008, 05:02, by kishor
Hi,
Now I am getting Adobe Reader’s ERROR: Wrong Operand Type.
In p_parseImage its getting Ora-1403 no data found.
The error is from line dbms_lob.read(pBlob, pLength, pHandle, l_data_raw);
Looks like pBlob is empty.
Any ideas?
Thanks
Kishor
5. PL_FPDF, 17 September 2008, 16:50, by Pierre-Gilles Levallois
Yes, I think it is because p_parseImage can’t find any image.
It seems that your UrlFactory don’t access the the image you want to integrate ?
Do you have any filtering between your Oracle DB server and the web server on which you want to get the image ?
6. PL_FPDF, 19 September 2008, 02:44, by kishor
Thanks for your advise.
My web server and DB server is same.
Instead of the server name, I used IP address and the following is happening.
I did debug and confirm the file has been accessed in URIfactory as it identified the File format as PNGF.
Instead of opening Acrobat reader, the message "File Download" box is appearing.
When I save the file (saved as .pdf) and try to open it, Acrobat Reader is giving message:
"There was an error opening this document. The File is damaged and could not be repaired."
Also, the AcroRd32.exe process remains loaded and has to be killed as it hangs.
If you need I can send you the generated PDF file. Please send me your email address.
Appreciate your advise. Thanks a lot for you time.
Kishor
7. PL_FPDF, 2 October 2008, 11:30, by Pierre-Gilles Levallois
Hi Kishor
This seems to be a problem in png conversion with the Oracle OrdImage Cartridge.
In PL_FPDF code ("getImageFromUrl" function), there is "on the fly" png conversion for all the images that are not in png format. But this seems not work with GIF format. And this format isn’t supported in the pdf.
Perhaps this is because the GIF files are interpreted as PNG by Oracle OrdImage cartridge ?
So the following test (in "getImageFromUrl" function) doesn’t pass ?
Perhaps this test matches with GIF Images ???
I have to digg in it...
HTH,
Pierre-Gilles.
8. PL_FPDF, 15 October 2008, 15:41, by Baskar
Im receiving the below error when executing the hello world program, please help me
Cause: FDPSTP failed due to ORA-20100: PL_FPDF error: Output : ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "APPS.XXEQ_PDF", line 1704
ORA-06512: at "APPS.XXEQ_PDF", line 3015
ORA-06512: at
9. PL_FPDF, 15 October 2008, 17:43, by Pierre-Gilles Levallois
it seems you have a problem in APPS.XXEQ_PDF procedure, no ?
The result of this error throws an error to PL_FPDF Output procedure.
10. PL_FPDF, 5 November 2008, 20:20, by jbkoyen
Bon Jour Pierre,
First of all thanks for sharing this package.
Regarding the PNG header check, I encountered some issues too.
It seems that the content of the "png_signature" variable is different interpreted in a multi-byte character database.
Maybe a "raw" datatype should be considered for these actions.
These are the results:
By the way the setting of parameter "set nls_length_semantics" to BYTE or CHAR doesn’t change the results.
I hope this helps (a bit ;-).
JB
11. PL_FPDF, 7 November 2008, 20:32, by jbkoyen
A short investigation in multibyte (unicode) characters reveals that for example in UTF-8 the first byte contains the (7 bits) US ASCII.
Above the 127 values another byte will be enabled, this explains the "strange" behavior of the length function for a varchar2 string in a multibyte environment.
HTH
JB
12. PL_FPDF.image, 9 November 2010, 02:53, by pwagiapu
I have written procedure using pl_fpdf that writes db content to pdf. It works very week on oracle 10g. However, same procedure not working on oracle 11g. The image function hangs the entire program. Is there known issues between image function of pl_fpdf and 11g? If so, is there any workaround for it?
Thanks,
Poli
2. PL_FPDF, 5 September 2008, 07:55, by krs
Hi,
I need to generate pdf from sql query,
please suggest how can i use/modify PL_FPDF to do this.
thanks& regards,
krs
1. PL_FPDF, 10 September 2008, 06:46, by krs
hi,
Is there any way to get the sql query output to pdf file.
thnaks
krs
3. PL_FPDF, 25 May 2009, 08:30, by Gobblin
this Version of FPDF is a great piece of work! Thanks a lot.
1. PL_FPDF, 25 May 2009, 15:14, by Pierre-Gilles Levallois
Thanks Gobblin.
Feel free to modify it and add features.
4. PL_FPDF, 20 July 2009, 17:53, by rwendel
Looks Great! I was wondering, was there a disadvantage to table loading some of the things like fonts and pagesizes or was this meant to be as close a port as possible and/or single package installation?
1. PL_FPDF, 11 August 2009, 10:39, by Pierre-Gilles Levallois
I did not us table loading for the fonts, because I wanted to keep a single package installation without needing to install a repository (i.E. tables end data).
This a choice. This means that all data for font sizing are in the package and so the package is bigger and less comprehensive, but this keeps the installation simple.
Regards,
5. PL_FPDF Kids object bug, 9 October 2009, 12:33, by arodichevski
Hi Pierre-Gilles
The PDF documents produced by the 0.9.1 version of the package read by some PDF readers give give the errors like those:
Error: Kids object (page 2) is wrong type (null)
Error: Page count in top-level pages object is incorrect
Error: Couldn’t read page catalog
The bug can be resolved changing in the procedure p_putpages the lines
kids := ’/Kids [’;
for i in 0..nb loop
with the following:
kids := ’/Kids [’;
for i in 0..nb-1 loop
Alexandre
1. PL_FPDF Kids object bug, 2 November 2009, 15:01, by Pierre-Gilles Levallois
Hi Alexandre,
Thanks for having dicovered this bug.I will correct it as soon as possible and put the new version inline.
Cheers,
6. PL_FPDF, 26 November 2009, 09:58, by Thorben
Bonjour!
I tried your terrific solution, but I experienced some problems with your examples. It would be really great, if you can help me out!
By trying the "Hello-World"-Example, I get the following Errormessage:
ORA-20100: PL_FPDF error: Output : ORA-06502: PL/SQL: numeric or value error
ORA-06512: in "TEST.PL_FPDF", Line 1916
ORA-06512: in "TEST.PL_FPDF", Line 3252
ORA-06512: in Line 7
Line 7 is the line: pl_fpdf.Cell(0,1.2,’Hello World’,0,1,’C’);
I checked the procedure’s paramters in the package, I can’t find the problem.
I also tried "pl_fpdf.test();", but there was the same mistake in Line 2, which is the .test()-Line.
Thank you very much for your help in advance!
Au revoir,
Thorben
7. PL_FPDF, 1 December 2009, 15:08, by TheHunger4More
Hi,
I am using your excellent package for generating PDF files from PL/SQL, but I have found two problems (one typo and one bug):
1) The error message in the "Cell" procedure incorrectly says error(’MultiCell : ’||sqlerrm), this should be error(’Cell : ’||sqlerrm);
2) The p_out procedure fails with ORA-06502: PL/SQL: numeric or value error: character string buffer too small when building a semi-complex tabular report. I assume this is because the combined length of the pstr parameter and the existing data exceeds 32k. You need to add logic in the p_out procedure that will handle more data by breaking up the strings and adding more rows to the internal index-by-tables.
Thanks!
8. PL_FPDF, 19 February 2010, 12:17, by fabio
Hi, my name is Fabio
I am using your great package but i have a very big problem. When i try to load an image i receive always the ’The file is damaged and could not be repaired’ error. I’ve tried laso with the ’ ’http://www.laclasse.com/v2/images/picto_laclassev2.png’ file. The generated code is the following :
%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<>
stream
2 J
0.56 w
BT /F1 12.0 Tf ET
BT /F2 16.0 Tf ET
q 283.46 0 0 53.14 28.34 513.78 cm /I1 Do Q
endstream
endobj
1 0 obj
<</Type /Pages
/Kids [3 0 R ]
/Count 1
/MediaBox [0 0 841.89 595.28]
>>
endobj
5 0 obj
<</Type /Font
/BaseFont /Helvetica
/Subtype /Type1
/Encoding /WinAnsiEncoding
>>
endobj
6 0 obj
<</Type /Font
/BaseFont /Helvetica-Bold
/Subtype /Type1
/Encoding /WinAnsiEncoding
>>
endobj
7 0 obj
<</Type /XObject
/Subtype /Image
/Width 80
/Height 15
/ColorSpace /DeviceRGB
/BitsPerComponent 8
/Filter /FlateDecode
/DecodeParms <
>
/Length >>
stream
endstream
endobj
2 0 obj
<<
/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
/Font <<
/F1 5 0 R
/F2 6 0 R
>>
/XObject <<
/I1 7 0 R
>>
>>
endobj
8 0 obj
<<
/Producer (PL_FPDF 0.9.2 portage pour Laclasse.com par P.G. Levallois de la version 1.53 de PHP/FPDF d’Olivier Plathey.)
/CreationDate (D:20100219121453)
>>
endobj
9 0 obj
<<
/Type /Catalog
/Pages 1 0 R
/OpenAction [3 0 R /FitH null]
/PageLayout /OneColumn
>>
endobj
xref
0 10
0000000000 65535 f
0000001878 00000 n
0000002397 00000 n
0000001661 00000 n
0000001739 00000 n
0000001965 00000 n
0000002061 00000 n
0000002162 00000 n
0000002521 00000 n
0000002696 00000 n
trailer
<<
/Size 10
/Root 9 0 R
/Info 8 0 R
>>
startxref
2799
%%EOF
please help me!!!
thanks
9. PL_FPDF, 13 November 2010, 15:33, by Esteban
Hello. How I can put a header on all pages of the pdf file. I have the parameter SetAutoPageBreak set to true. Can you help me with an example of the procedure in the header. Thanks for the reply.
1. PL_FPDF, 15 November 2010, 12:31, by Pierre-Gilles Levallois
Hi,
There is a proc that allows you to bind a hook for your header procedure :
pl_fpdf.setheaderproc(’Mypackage.YourHeaderHook’);
In the 0.9.3 version I added sample code that shows how to use this proc. Note that ’YourHeaderHook’ must have public specs in the ’Mypackage’ plsql package.
The code below is copied from the 0.9.3 new version.
sincerly.
HTH.
2. PL_FPDF, 16 November 2010, 16:54, by Esteban
Thanks for the help
10. PL_FPDF, 21 January 2011, 00:49, by milk
Hi,
I try to use your package, but I’ve encountered two basic problems. I want to make a simple print of employees in the table from the Oracle database with SQL.Please help with the following problems.
1. If the employee name longer than the cells in the table, crossing the next cell in the tables.
2.How to print the table header on each page.
Please help. Thanks.
11. PL_FPDF, 31 January 2011, 13:35, by Henk
Hallo Pierre-Gilles,
I use your version of FDPF to enable students to ask for exemption for certain courses. I let them upload proof of passing comparable courses. But then I come across a limitation: I can get only one (1) link per page to work. And sometimes they have several documents (grade lists, diplomes etc)
Can you give a hint on how to enhance the link (url)possibilities in PL_FPDF?
Kind regards,
Henk Op den Brouw
Tilburg University.