Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Apex Barcodes

2721579Jul 28 2014 — edited Aug 6 2014

Hello everyone,

I'm looking for a nice and simple way to generate barcodes in Oracle Apex 4.2.5. so I started browsing the web and found numerous threads which were more or less helpfull.

Finally I found this demo application which I considered clearly and well structured.

https://apex.oracle.com/pls/otn/f?p=31517:105:113800502836403:::RP%2C::

1. Create the procedure in SQL workshop

create or replace PROCEDURE "BARCODE_PR" ( code39text IN VARCHAR2, code39label IN VARCHAR2, code_height IN NUMBER DEFAULT 20, code_width IN NUMBER DEFAULT 1 ) IS v_str VARCHAR2 (200) := ''; v_barstr VARCHAR2 (1) := ''; v_barstrcode VARCHAR2 (10) := ''; v_barstrcodeselect VARCHAR2 (10) := ''; v_label VARCHAR2 (10) := ''; x_pos NUMBER := 0; x_textstep NUMBER; x_bigstep NUMBER (10); x_smallstep NUMBER (10); x_width NUMBER := 0; y_height NUMBER; BEGIN

-- setting values from the page to the internal PLSQL variables.

   v_str := UPPER (code39text);

   v_label := UPPER (code39label);

   y_height := (code_height);

   x_smallstep := (code_width);

   x_bigstep := 3 * (code_width);

   x_textstep := (x_smallstep * 2 + x_bigstep * 2) / 3;

-- generating header of svg file

OWA_UTIL.mime_header (ccontent_type => 'image/svg+xml',

bclose_header      => FALSE,

ccharset           => 'utf-8'

);

   HTP.p ('Cache-Control: no-cache');

OWA_UTIL.http_header_close;

-- generating SVG file

   HTP.p ('<?xml version="1.0" encoding="iso-8859-1"?>');

   HTP.p (   '<svg width="100%" height="100%" xmlns="'

          || 'http://www.w3.org/2000/svg" '

          || 'xmlns:xlink="http://www.w3.org/1999/xlink"'

          || ' xmlns:a="http://ns.adobe.com'

          || '/AdobeSVGViewerExtensions/3.0/" >'

         );

-- if I want to have label in the barcode,

-- I need to declare style of text...

   IF v_label = 'YES'

   THEN

      HTP.p ('<style type="text/css" >');

      HTP.p ('<![CDATA[ ');

      HTP.p ('.textlabel {font-size:8.0pt  ; '

          || 'font-family:Helvetica ;}'

            );

      HTP.p (' ]]>');

      HTP.p (' </style> ');

   END IF;

   HTP.p (' <g>');

/*

every char is internally coded to abcd codeing , that:

a means thick black line in the barcode

b means thin black line in the barcode

c means thick white line (bigger space)

d means thin white line (small space)

*/

   FOR i IN 1 .. LENGTH (v_str)

   LOOP

      v_barstr := SUBSTR (v_str, i, 1);

      v_barstrcode :=

         CASE v_barstr

            WHEN '1'

               THEN 'adbcbdbdad'

            WHEN '2'

               THEN 'bdacbdbdad'

            WHEN '3'

               THEN 'adacbdbdbd'

            WHEN '4'

               THEN 'bdbcadbdad'

            WHEN '5'

               THEN 'adbcadbdbd'

            WHEN '6'

               THEN 'bdacadbdbd'

            WHEN '7'

               THEN 'bdbcbdadad'

            WHEN '8'

               THEN 'adbcbdadbd'

            WHEN '9'

               THEN 'bdacbdadbd'

            WHEN '0'

               THEN 'bdbcadadbd'

            WHEN 'A'

               THEN 'adbdbcbdad'

            WHEN 'B'

               THEN 'bdadbcbdad'

            WHEN 'C'

               THEN 'adadbcbdbd'

            WHEN 'D'

               THEN 'bdbdacbdad'

            WHEN 'E'

               THEN 'adbdacbdbd'

            WHEN 'F'

               THEN 'bdadacbdbd'

            WHEN 'G'

               THEN 'bdbdbcadad'

            WHEN 'H'

               THEN 'adbdbcadbd'

            WHEN 'I'

               THEN 'bdadbcadbd'

            WHEN 'J'

               THEN 'bdbdacadbd'

            WHEN 'K'

               THEN 'adbdbdbcad'

            WHEN 'L'

               THEN 'bdadbdbcad'

            WHEN 'M'

               THEN 'adadbdbcbd'

            WHEN 'N'

               THEN 'bdbdadbcad'

            WHEN 'O'

               THEN 'adbdadbcbd'

            WHEN 'P'

               THEN 'bdadadbcbd'

            WHEN 'Q'

               THEN 'bdbdbdacad'

            WHEN 'R'

               THEN 'adbdbdacbd'

            WHEN 'S'

               THEN 'bdadbdacbd'

            WHEN 'T'

               THEN 'bdbdadacbd'

            WHEN 'U'

               THEN 'acbdbdbdad'

            WHEN 'V'

               THEN 'bcadbdbdad'

            WHEN 'W'

               THEN 'acadbdbdbd'

            WHEN 'X'

               THEN 'bcbdadbdad'

            WHEN 'Y'

               THEN 'acbdadbdbd'

            WHEN 'Z'

               THEN 'bcadadbdbd'

            WHEN '-'

               THEN 'bcbdbdadad'

            WHEN '+'

               THEN 'bcbdbcbcbd'

            WHEN '*'

               THEN 'bcbdadadbd'

            WHEN '/'

               THEN 'bcbcbdbcbd'

            WHEN '%'

               THEN 'bdbcbcbcbd'

            WHEN '.'

               THEN 'acbdbdadbd'

            WHEN '$'

               THEN 'bcbcbcbdbd'

            ELSE 'cccddddddd'

         END;

      FOR j IN 1 .. LENGTH (v_barstrcode)

      LOOP

v_barstrcodeselect := (SUBSTR (v_barstrcode, j, 1));

--drawing thick black line

         IF v_barstrcodeselect = 'a'

         THEN

            HTP.p (   '<rect height="'

                   || y_height

                   || '" width="'

                   || x_bigstep

                   || '" x="'

                   || x_pos

                   || '" y="0"/>'

                  );

            x_pos := x_pos + x_bigstep;

         END IF;

--drawing thin black line

         IF v_barstrcodeselect = 'b'

         THEN

            HTP.p (   '<rect height="'

                   || y_height

                   || '" width="'

                   || x_smallstep

                   || '" x="'

                   || TO_CHAR (x_pos)

                   || '" y="0"/>'

                  );

            x_pos := x_pos + x_smallstep;

         END IF;

--drawing thick white line

         IF v_barstrcodeselect = 'c'

         THEN

            x_pos := x_pos + x_bigstep;

         END IF;

--drawing thin white line

         IF v_barstrcodeselect = 'd'

         THEN

            x_pos := x_pos + x_smallstep;

         END IF;

      END LOOP;

-- write one char of label

      IF v_label = 'YES'

      THEN

         HTP.p (   '<text class="textlabel" x="'

                || x_textstep

                || '" y="'

                || (y_height + 10)

                || '">'

                || v_barstr

                || '</text>'

               );

      END IF;

      x_pos := x_pos + x_smallstep;

      x_textstep := x_textstep + (x_smallstep * 6 + x_bigstep * 3) + 3;

   END LOOP;

   HTP.p (' </g>');

   HTP.p (' </svg> ');

END barcode_pr;

2. Create the application process in the shared components

BEGIN

   barcode_pr (:t_code_text, :t_code_label, :t_code_height, :t_code_width);

apex_application.g_unrecoverable_error := true;

END;

3. Create the 3 application items in the shared components

T_CODE_TEXT,T_CODE_LABEL,T_CODE_HEIGHT,T_CODE_WIDTH

4. Create a classic report based on the coy&pasted query and set the column attributes to display as standard report column

SELECT empno, ename,

  '<embed '

  || 'src=https://apex.oracle.com/pls/apex/f?p=&APP_ID.:0:'

  || '&SESSION.:GET_BARCODE:&DEBUG.::'

  || 'T_CODE_TEXT,T_CODE_LABEL,T_CODE_HEIGHT,T_CODE_WIDTH:'

  || ename

  || ',Yes,20,1'

  || ' '

  || 'width=200 height=45 '

  || 'type=image/svg+xml />' barcode

  FROM emp

When I run the application the column where the barcode should appear is simply empty.

There's definitely nothing wrong with my browser as I can see the barcodes in the demo app.

The procedure itself works fine. For testing I created a button that executes the process and shows the barcode for that one specific string on a new page....

I stopped counting how many times I followed the instructions and deleted the application because it was not working and started all over again.

So, I'd really appreciate if anyone could give me a hint which part of the demo I missed!

Thanks a lot in advance!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 3 2014
Added on Jul 28 2014
21 comments
10,007 views