Pilooz / pl_fpdf

PL-SQL library to generate pdf files from Oracle database.
43 stars 33 forks source link

Images don't work #11

Open just-doit opened 6 years ago

just-doit commented 6 years ago

Procedure p_putstream(pData in out NOCOPY blob) doesn't handle the blob data correctly. By reading them into a varchar2 variable, it get's converted into the hex representation.

The following change works for me:

PROCEDURE p_putstream (pdata IN OUT NOCOPY BLOB)
   IS
      offset              INTEGER := 1;
      lv_content_length   NUMBER := DBMS_LOB.getlength (pdata);
      buf_size            INTEGER := 2000;
      buf                 RAW (2000);
   BEGIN
      p_out ('stream');

      -- read the blob and put it in small pieces in a varchar
      WHILE offset <= lv_content_length
      LOOP
         DBMS_LOB.read (pdata, buf_size, offset, buf);
         p_out (UTL_RAW.cast_to_varchar2 (buf), FALSE);
         offset := offset + buf_size;
      END LOOP;

      -- put a CRLF at te end of the blob
      p_out (CHR (10), FALSE);
      p_out ('endstream');
   EXCEPTION
      WHEN OTHERS
      THEN
         error ('p_putstream : ' || SQLERRM);
   END p_putstream; 

I've changed the < into a <= in the while loop as well, btw.

j-christ commented 3 years ago

I found and fixed the same issue in the same way, and then saw this comment.