`
wuhuizhong
  • 浏览: 681231 次
  • 性别: Icon_minigender_1
  • 来自: 中山
社区版块
存档分类
最新评论

Free PDF package for PL/SQL

 
阅读更多

I'm sure you've heard about PL/PDF, the PL/SQL-based solution that allows you to create PDF documents directly from your database. PL/PDF is a good product, but it is not free (the current license price is USD 600 per database server).

However, I just came across a free alternative called PL_FPDF, which is a PL/SQL port of the PHP-based FPDF. The latest version of PL_PDF seems to have been released about a year ago, and I can't believe I haven't seen or heard about it before now... !

UPDATE, MARCH 2011: Also check out this alternative PDF generation package by Anton Scheffer. It seems simpler and more robust than the PL_FPDF package, but may lack certain features. Be sure to evaluate both!

PL_FPDF is just a single package, so installation is a snap. Note that it uses the ORDImage data type to place images in PDF documents, so if you are running Oracle XE (which doesn't include the ORDImage data type), you need to comment out the few procedures that deal with this data type (and obviously you will not be able to include images in your PDF documents...).

After a few hours of experimentation, I was able to produce a semi-complex PDF document that tests a number of features in PL_FPDF. My test script is included below for your convenience. Note that the default assumption is that output goes to the web browser via the HTP package, but it should be trivial to add a procedure that saves the resulting BLOB to a database table instead.

Note: Since PL_FPDF is based on FPDF, I found the online documentation for FPDF (see link above) very useful in order to find out how the API for PL_FPDF works.

create or replace procedure test_pl_fpdf
as
l_text varchar2(32000) := 'First, reduce actual complexity by eliminating unnecessary features and then hiding what you can''t eliminate. Secondly, reduce perceived complexity by minimizing visual noise and reusing elements. And finally, use the blank state to help orient users. Minimizing complexity in the user interface will help people learn your application more quickly, use it more effectively and be happier all the while.

As jazz musician Charles Mingus said, "Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that''s creativity."';

begin

-- create document in portrait mode, use measurements in millimeters (mm), and use the A4 page format
pl_fpdf.FPDF('P','mm','A4');
pl_fpdf.openpdf;

-- display full page, two facing pages 
pl_fpdf.setdisplaymode ('fullpage', 'two');

-- a procedure that will be called at the end of each page
-- pl_fpdf.setfooterproc('demo.test_pdf_footer');  

pl_fpdf.AddPage();

-- set up some headers
pl_fpdf.SetFillColor(255,128,128);
pl_fpdf.SetFont('Arial','B',14);
--this header will be filled with the background color 
pl_fpdf.cell(40,7,'TABLESPACE', 1, 0, 'L', pfill => 1);
pl_fpdf.cell(40,7,'CONTENTS', 1);
pl_fpdf.cell(40,7,'INITIAL EXTENT', 1, 1);

pl_fpdf.SetFont('Arial','',14);

for l_rec in (select tablespace_name, contents, initial_extent from dba_tablespaces order by 1) loop

pl_fpdf.settextcolor(0,0,0);
pl_fpdf.cell(40,7,l_rec.tablespace_name,'B');
pl_fpdf.cell(40,7,l_rec.contents,'B');
-- some conditional formatting
if l_rec.initial_extent > 66000 then
pl_fpdf.settextcolor(255,0,0);
else
pl_fpdf.settextcolor(0,0,0);
end if;
pl_fpdf.cell(40,7,l_rec.initial_extent,'B', 1, 'R');

end loop;

-- a page that shows how to position chunks of text (with automatic line breaks) on the page

pl_fpdf.AddPage();

pl_fpdf.SetFont('Arial','B',16);
pl_fpdf.setxy (100, 20);
pl_fpdf.Cell(10,10,'Cool Quote 1:');

pl_fpdf.setxy (100, 50);
pl_fpdf.SetFont('Times','',12);
pl_fpdf.multicell(100,0,l_text);


pl_fpdf.SetFont('Arial','B',16);
pl_fpdf.setxy (10, 130);
pl_fpdf.Cell(10,10,'Cool Quote 2:');

pl_fpdf.setxy (10, 150);
pl_fpdf.SetFont('Times','',12);
pl_fpdf.multicell(100,0,l_text);

-- a page that demonstrates some simple drawing with lines and rectangles

pl_fpdf.AddPage();

pl_fpdf.SetFont('Arial','B',14);
pl_fpdf.Cell(0,0,'And now, some beautiful line art...',0,1,'C');

pl_fpdf.line (10,10, 50, 50);
pl_fpdf.rect (50,50, 50, 50);
pl_fpdf.setdrawcolor(0,255,0);
pl_fpdf.line (150,150, 50, 50);

pl_fpdf.setdrawcolor(0,0,0);

-- a simple table of employees, without headings

pl_fpdf.AddPage();

for l_rec in (select empno, ename from emp order by ename) loop

pl_fpdf.cell(40,7,l_rec.empno, 'B');
pl_fpdf.cell(40,7, l_rec.ename, 'B', 1);

end loop;


pl_fpdf.SetFont('Arial','B',48);
pl_fpdf.settextcolor(0,0,255);

pl_fpdf.setxy (100, 250);

pl_fpdf.cell(80,10,'THE END', palign => 'C');

pl_fpdf.Output();

end test_pl_fpdf;
 

Conclusion: While PL/PDF is more advanced in terms of features, PL_FPDF might be for you if you just need some simple PDF reports in your application.

 

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

 

分享到:
评论

相关推荐

    oracle面试笔记[文].pdf

    3. **PL/SQL程序加密**:Oracle提供了WRAP工具,用于对PL/SQL代码进行加密,以保护源代码不被查看。 4. **FUNCTION、PROCEDURE与PACKAGE的区别**: - FUNCTION:是无返回值或返回一个值的PL/SQL代码块。 - ...

    Oracle数据库面试题及答案

    知识点:FUNCTION、PROCEDURE 和 PACKAGE 是 PL/SQL 中的三个基本概念,function 和 procedure 是代码的集合,而 PACKAGE 是一组 function 和 procedure 的集合。 5. 解释 TABLE Function 的用途 答案:TABLE ...

    oracle performance tuning

    6. **处理过大的匿名PL/SQL代码块**:找出长度超过500个字符的匿名PL/SQL代码块,并考虑将其转换为存储过程或保留在共享池中。 ```sql SELECT sql_text FROM v$sqlarea WHERE command_type = 47 AND length(sql_...

    PHP Oracle.rar

    6. **PL/SQL调用** PHP还可以执行Oracle的PL/SQL块,这需要用到oci_parse并传递包含PL/SQL的字符串。例如: ```php $stmt = oci_parse($conn, 'BEGIN package_name.procedure_name(:param1, :param2); END;'); ...

    Oracle性能调整的十大要点

    - 将大型匿名PL/SQL代码块转换为小型匿名PL/SQL代码块,并调用存储过程以减少内存碎片。 - 对于特别大的匿名PL/SQL代码块,可以考虑使用`dbms_shared_pool.keep()`函数将其保留在Shared Pool中。 **2. Execution ...

    数据库常用SQL语法

    当需要立即刷新物化视图时,可以使用以下PL/SQL命令。 #### PL/SQL命令分析: ```sql EXEC DBMS_MVIEW.REFRESH('TD_M_DEPART', 'FAST'); ``` - **功能**:手动刷新名为 `TD_M_DEPART` 的物化视图。 - **参数**: ...

    数据库经常出的面试题

    查看PL/SQL Package中的错误信息 - **知识点**:使用`SHOW ERRORS`命令可以查看PL/SQL包中的编译错误或其他问题。这对于调试非常有用。 #### 27. 分析表和索引的状态 - **知识点**:`ANALYZE`命令用于收集表和...

    ora分析脚本

    - ash_sql <sql_id> Show all ash rows group by sampli_time and event for the specified sql_id - [-u <user/passwd>] degree degree of objects for a given user - [-u <user/passwd>] colstats stats for ...

    北京-ORACLE畅享互联科技

    如果在编译PL/SQL Package时遇到错误,可以通过以下命令查看错误信息:`SHOW ERRORS PACKAGE pkg_name;` 或者使用Oracle Enterprise Manager等工具来查看更详细的错误报告。 ### 10. 如何搜集表的各种状态数据 ...

    sql面试题\oracle面试题目

    显示PL/SQL Package编译错误 - 使用`DBMS_OUTPUT`包显示错误信息。 - 使用`DBMS_SERVEROUTPUT.ENABLE`启用输出。 #### 47. 搜集表的各种状态数据 - 使用`DBMS_STATS.GATHER_TABLE_STATS`命令。 #### 48. 启动...

    Oracle DBA 笔试题

    4. 开发和管理中常用的工具包括Toad、PL/SQL Developer、SQL Developer、Oracle Enterprise Manager等。 5. 获取Oracle信息的途径有官方文档、技术论坛(如Oracle Technet、ITPUB)、博客、邮件列表等。 6. 解决一...

    oracle恢复工具-FY_Recover_Data

    PL/SQL procedure successfully completed 从红色字体可以看出,恢复72622条,刚好是truncate前业务表中记录数,恢复临时表为:SYS.TRUNTAB1$$2 第七步:查看输出内容和构造表名: insert into truntab1 ...

Global site tag (gtag.js) - Google Analytics