|« Write fast and efficient PLSQL - DBMS_PROFILER||Draw plus and cross sign into PDF via PLSQL using PL_FPDF »|
Draw Triangle directly into PDF via PLSQL using PL_FPDF
Posted by Zahid Kareem on January 9, 2016.
PL_FPDF is a very powerful open source PL/SQL library. It can generate PDF files directly from PL/SQL and is very useful with the web applications developed in Oracle Application Express.
For details on PL_FPDF please see: http://www.erasme.org/PL-FPDF,1337
However, once I needed to draw a triangle into my PDF file which was being generated from PL/SQL code, I found out that there is no procedure in the library to draw a triangle. So, I decided to write one for myself.
Here is that piece of code:
PROCEDURE triangle ( px NUMBER, -- X position of the triangle py NUMBER, -- Y position of the triangle psize NUMBER, -- size of the triangle porientation VARCHAR2 DEFAULT 'U', -- The orientation of triangle pstyle VARCHAR2 DEFAULT 'D' ) IS point_1 point; point_2 point; point_3 point; points tab_points; halfsize NUMBER := ROUND (psize / 2, 2); doublesize NUMBER := ROUND (psize * 2, 2); BEGIN IF porientation = 'L' THEN point_1.x := px - halfsize; point_1.y := py - psize; point_2.x := point_1.x + psize; point_2.y := point_1.y + psize; point_3.x := point_1.x; point_3.y := point_1.y + doublesize; ELSE point_1.x := px - halfsize; point_1.y := py + halfsize; point_2.x := point_1.x + halfsize; point_2.y := point_1.y - psize; point_3.x := point_1.x + psize; point_3.y := point_1.y; END IF; points (0) := point_1; points (1) := point_2; points (2) := point_3; poly (points, TRUE, pstyle); END triangle;
Add the header of this procedure i.e. name and arguments in the PL_FPDF package and then include the code above into the PL_FPDF package body and then use it where ever you want.