Thursday, August 1, 2019



How to Create PDF Report Using PL/SQL



Before writing and giving this example to create a PDF report using PL/SQL in Oracle, I researched a lot on Google, but I did not find any proper example. So I thought I should give an example to generate a PDF report file using PL/SQL. To do this first, you need to install pdf_builder_pkg database package in your schema.

you can download the package from pdf_build_pkg link.

Now you have already installed the database package. Now you can write the procedure or function to create a PDF report using PL/SQL. Here below is the example PL/SQL block.



Example Function which return pdf file

------------------------------------------------------------------------------------------------------------

create or replace function "DOWNLOAD_REPORT"
return BLOB
is
pdf_blob blob;
begin
 /* First line to initialize the package*/
 pdf_builder_pkg.init;

 /* Set the font to bold for heading*/
 pdf_builder_pkg.set_font ('helvetica', 'b');

 /* Write a line using pdf_builder_pkg.write procedure*/ 
 pdf_builder_pkg.write ('Employee Report');

 /* Set the font to normal */

 pdf_builder_pkg.set_font ('helvetica');
 pdf_builder_pkg.
 write ('Printed Date: ' || SYSDATE, -1, p_alignment => 'right');
pdf_builder_pkg.
 write (
 '________________________________________________________________________________');
pdf_builder_pkg.write ('<h1> Heading </h1>');
 /* Saving the PDF file by passing directory name and file name */

pdf_blob := pdf_builder_pkg.get_pdf();

return pdf_blob;

end;


------------------------------------------------------------------------------------------------------------



You can find the PDF file named emp_report.pdf at your directory location.  The PDF report will look like as shown below:




For more reference of PDF_build package visit https://technology.amis.nl/2012/04/11/generating-a-pdf-document-with-some-plsql-as_pdf_mini-as_pdf3/  


Thanks,

Happy Coding 👱













No comments:

Post a Comment