AS_PDF, generating a PDF-document with some plsql

92

I’ve written a small package (1500 lines). But with this package you can generate a PDF-document with a few lines of PL/SQL code. It’s small because it lacks some functionality. It can only use the standard PDF fonts, and that means that it can only use the WINDOWS-1252 encoding/characterset. But besides that it’s fairly complete.

For instance.

begin
as_pdf_mini.init;
as_pdf_mini.write( 'Some text with a newline-character included at this "
" place.' );
as_pdf_mini.write( 'Normally text written with as_pdf_mini.write() is appended after the previous text. But the text wraps automaticly to a new line.' );
as_pdf_mini.write( 'But you can place your text at any place', -1, 700 );
as_pdf_mini.write( 'you want', 100, 650 );
as_pdf_mini.write( 'You can even align it, left, right, or centered', p_y => 600, p_alignment => 'right' );
as_pdf_mini.save_pdf;
end;

Some text

And

begin
as_pdf_mini.init;
for i in 1 .. 10
loop
as_pdf_mini.horizontal_line( 30, 700 - i * 15, 100, i );
end loop;
for i in 1 .. 10
loop
as_pdf_mini.vertical_line( 150 + i * 15, 700, 100, i );
end loop;
for i in 0 .. 255
loop
as_pdf_mini.horizontal_line( 330, 700 - i, 100, p_line_color => to_char( i, 'fm0x' ) || to_char( i, 'fm0x' ) || to_char( i, 'fm0x' ) );
end loop;
as_pdf_mini.save_pdf;
end;

Some lines

And jpg and png images, from a url, the file-system or from a database blob can be included:

Example of an image

And to show the standard PDF fonts

begin
as_pdf_mini.init;
as_pdf_mini.write( 'The mini version of AS_PDF is restricted to the 14 standard PDF-fonts and the WINDOWS-1252 encoding.' );
as_pdf_mini.set_font( 'helvetica' );
as_pdf_mini.write( 'helvetica, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 700 );
as_pdf_mini.set_font( 'helvetica', 'I' );
as_pdf_mini.write( 'helvetica, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'helvetica', 'b' );
as_pdf_mini.write( 'helvetica, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'helvetica', 'BI' );
as_pdf_mini.write( 'helvetica, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'times' );
as_pdf_mini.write( 'times, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 625 );
as_pdf_mini.set_font( 'times', 'I' );
as_pdf_mini.write( 'times, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'times', 'b' );
as_pdf_mini.write( 'times, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'times', 'BI' );
as_pdf_mini.write( 'times, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'courier' );
as_pdf_mini.write( 'courier, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 550 );
as_pdf_mini.set_font( 'courier', 'I' );
as_pdf_mini.write( 'courier, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'courier', 'b' );
as_pdf_mini.write( 'courier, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'courier', 'BI' );
as_pdf_mini.write( 'courier, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
--
as_pdf_mini.set_font( 'courier' );
as_pdf_mini.write( 'symbol:', -1, 475 );
as_pdf_mini.set_font( 'symbol' );
as_pdf_mini.write( 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf_mini.set_font( 'courier' );
as_pdf_mini.write( 'zapfdingbats:', -1, -1 );
as_pdf_mini.set_font( 'zapfdingbats' );
as_pdf_mini.write( 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
--
as_pdf_mini.set_font( 'times', 'N', 20 );
as_pdf_mini.write( 'times, normal with fontsize 20pt', -1, 400 );
as_pdf_mini.set_font( 'times', 'N', 6 );
as_pdf_mini.write( 'times, normal with fontsize 5pt', -1, -1 );
as_pdf_mini.save_pdf;
end;

Fonts

Or you can write a procedure: refcursor in, pdf out

Refcursor

The package: as_pdf_mini
But see also it successor as_pdf3

Share.

About Author

92 Comments

  1. Hi Anton,
    I like the AS_PDF3 script.
    I am trying to use the procedure SET_BK_COLOR to change the background color on some lines in my PDF document, but couldn’t get any result showed up. Could you offer any advice?

    Thank you in advance.

    Amy

  2. Hi Anton,

    Thank you for sharing your script.
    It is working like a charm.

    I have just one question:
    How can we add a page break while writing into the pdf file ?

    Thank you in advance & best regards,
    Zakaria

  3. I am trying to create pdf using this and I am not able to do it. It says invalid directory path. Can any one help me out in this.
    Thanks

  4. Anton

    thank you very much for your quick reply and for having confirmed that the solution could be fine.
    I download the new version of as_pdf but i didn’t see the show_pdf function. Why?
    Franco

    • Anton Scheffer on

      @Franco
      As I said, “Not complete backward compatible”. I had no need for that procedure, so I didn’t included it.
      But I think you can add the old show_pdf procedure yourself.

  5. Hi Anton
    First of all tank you very much for your usefull work.
    I had a problem with some browser that not recongnized the pdf file.
    I solved the problem with a little modification to a “show”  procedure and i’d like to know your opinion about it.
    —- original “show” function
    procedure show_pdf
    is
    begin
    finish_pdf;
    owa_util.mime_header( ‘application/pdf’, false );
    htp.print( ‘Content-Length: ‘ || dbms_lob.getlength( pdf_doc ) );
    htp.print( ‘Content-disposition: inline’ );
    htp.print( ‘Content-Description: Generated by as_xslfo2pdf’ );
    owa_util.http_header_close;
    wpg_docload.download_file( pdf_doc );
    dbms_lob.freetemporary( pdf_doc );
    end;
    —— modified “show” function
    procedure show_pdf (p_name in varchar2)
    is
    begin
    finish_pdf;
    owa_util.mime_header( ‘application/pdf’, false );
    htp.print( ‘Content-Length: ‘ || dbms_lob.getlength( pdf_doc ) );
    — modified and added line
    htp.print( ‘Content-disposition: attachment; filename=”‘||p_name||'”‘ );
    htp.print( ‘Content-type: application/pdf’ );
    —-
    htp.print( ‘Content-Description: Generated by as_xslfo2pdf’ );
    owa_util.http_header_close;
    wpg_docload.download_file( pdf_doc );
    dbms_lob.freetemporary( pdf_doc );
    end;
     

    • Anton Scheffer on

      @Franco G.
      Nothing wrong with your version. It does not do exactly the same as my version, but if it works for you, use it!

  6. Hi Anton,
    Just came across the as_pdf  package.  Thanks very much for sharing.
    Is there possibly a simply was to convert an html page to a PDF without re coding and formatting each line?
    Mike
     

  7. Mohammed Haris on

    Anton,
    Do you have any code for prototyping this new version, like you had in your previous one ?
     

  8. Anton,
    Thank you this has resolved this problem.  Unfortunately now I am looking at one that makes no sense to me. Instead of the following lines ending up generating 1 line in the PDF they generate multiple lines on different pages.  The intent is that I output the header and footer on each page and then start outputting the body.  Any ideas on what is causing this?
    — this is the page header
    as_pdf2a.write(‘Output by XYZ’,p_y=>500, p_x=>350); –, p_alignment=> ‘center’);
    — This is the page footer
    as_pdf2a.write(‘Date: ‘||TO_CHAR(pi_as_of,’dd-MON-rr HH:MI AM’),p_y=>40, p_x=>30, p_alignment=> ‘left’);
    as_pdf2a.set_font(p_family=> ‘TIMES’, p_style=> ‘N’, p_fontsize_pt=> 18);
    as_pdf2a.write(‘Output by XYZ’,p_y=>40, p_x=>350, p_alignment=> ‘center’);
    as_pdf2a.set_font(p_family=> ‘TIMES’, p_style=> ‘N’, p_fontsize_pt=> 10);
    as_pdf2a.write(‘Page: ‘||pi_page_nbr,p_y=>40, p_x=>740, p_alignment=> ‘right’);

    • Anton Scheffer on

      The write procedure isn’t meant for outputting text outside the page margins. You have to use put_txt for that.

  9. Anton,
    I have been using your as_pdf_mini package for a prototype that I am working on.  Once you get use to the addressing scheme it works quite well.  Unfortunately I have run into what I think is a bug and wanted to run it past you.
    I have a large varchar2(4000) text field that I am trying to display.  The first several lines of the field are quite long.  Each line has a CR/LF at the end then a blank line that just has a CR/LF.  The lines start wrapping as I would expect but then the calculations that the write function performs doesn’t take into account that a line might wrap more than one time.  When that occurs the lines end up overlapping.
    I generated 500 words through lipsum.com and pasted that into a variable in your example1.  When you do that the problem is apparent.  Any thoughts on how to correct this?
    Thanks,
    Tom

  10. Hi Anton,
    No, that select statement wil display ‘day1′ in the collumn. I want to display ‘1’. When I try putting just
    select day1 “1”, day2 “2”
    I get in the collumn _x0031_ and _x0032_

  11. Hi Anton,
    When I try to put literal names lin my column name of my select statement like: select day1 “1” from dual; I get some kind of code in my table made with refcursor.
    How do I get my 1 and not the codes?

  12. Anton,

    Great package.

    I think someone has asked this already…

    In one of you examples you have

    t_logo varchar2(32767) :=
    ‘/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkS’ ||….
     
    where the text string is an image of the AMIS logo.  How or what tools did you use to convert the image (logo) in to the text string?
     
     

    • Anton Scheffer on

      declare
      bf bfile;
      x blob;
      img varchar2(32767);
      begin
      bf := bfilename( ‘MY_DIR’, ‘amis_logo.jpg’ );
      dbms_lob.open( bf, dbms_lob.LOB_READONLY );
      dbms_lob.createtemporary( x, true );
      dbms_lob.loadfromfile( x, bf, dbms_lob.LOBMAXSIZE );
      dbms_lob.close( bf );
      img := utl_raw.cast_to_varchar2( utl_encode.base64_encode( x ) );
      dbms_lob.freetemporary( x );
      dbms_output.put_line( replace( img, chr(13) || chr(10), ”’ ||’ || chr(13) || chr(10) || ‘ ”’ ) );
      end;

  13. Anton,
    I made a slight hack to your code which allows me to add content to previous pages. I found this was necessary to do page numbering such as “Page 3 of  7″ because in my case, there is no way to know that there will be 7 pages until you are actually on page 7.  Thanks for making your code available. I’ve learned a lot just by reading it..

  14. Hi anton, I update You about my case. I find the problem!
    IN PB I use a OLE OBJ ,  when i tstore the image insert other data about the formt (jpg, bitmap etc etc) . I try to load jpg file directly in blob variable and after store it in DB; using this way I diplay correctly my jpg in pdf.
    Thank a lot for you suggest.
    Have a good Day
    Francesco

  15. thans Anton, using your Script I obtain :
     
    Not Null
    length15872
    this is not a jpg I can handle
    this is also not a jpg I can handle

    Not Null
    length15872
    this is not a jpg I can handle
    this is also not a jpg I can handle
     
    I open the jpg (original) file with hex editor, the file start with : FF D8 ( a bitmap is true?) , the hex of the DB start with “D0 CF”.
    I use PowerBuilder application to put the image into db; i think pb manipulate the data . I investigate in this way.
    thanks a lot, have a good Day
    Francesco

     
     

  16. Sorry Anton, I’m crazy…. ;-) the correct code is:

    declare
    v_blob blob;
    begin
    as_pdf_mini.init;
    as_pdf_mini.set_format(‘A4′,’L’);
    select c2 into v_blob from test where c1=’a';
    if v_blob is null  then
    as_pdf_mini.write(‘NULLLLLL’, 10,10);
    else
    as_pdf_mini.write(‘Not Null’, 10,10);
    as_pdf_mini.put_image(v_blob, 10,100,400,300);
    end if;
    as_pdf_mini.save_pdf (null,’a.pdf’);
    end;
    In the pdf I find the ‘not null’ string only.
    thanks Francesco

    • Anton Scheffer on

      @francesco
      You can with this script check if your jpg is a realy a jpg, or a least a jpg as_pdf_mini can handle:
      declare
      v_blob blob;
      begin
      select c2 into v_blob from test where c1=’a';
      if v_blob is null then
      dbms_output.put_line(‘NULLLLLL’);
      else
      dbms_output.put_line(‘Not Null’);
      dbms_output.put_line( ‘length’ || dbms_lob.getlength( v_blob ) );
      if ( dbms_lob.substr( v_blob, 2, 1 ) != hextoraw( ‘FFD8′ ) — SOI Start of Image
      or dbms_lob.substr( v_blob, 2, dbms_lob.getlength( v_blob ) – 1 ) != hextoraw( ‘FFD9′ ) — EOI End of Image
      )
      then
      dbms_output.put_line( ‘this is not a jpg I can handle’ );
      end if;
      if dbms_lob.substr( v_blob, 2, 3 ) not in ( hextoraw( ‘FFE0′ ) — a APP0 jpg
      , hextoraw( ‘FFE1′ ) — a APP1 jpg
      )
      then
      dbms_output.put_line( ‘this is also not a jpg I can handle’ );
      end if;
      end if;
      end;

  17. Hi anton. I create a test case.
    Create table test vith (c1 varchar2(10),c2 blob));
    Insert a jpg in c2 with c1=’a’.
    after I run:

    —————————————————-
    declare
    v_blob blob;
    begin
    as_pdf_mini.init;
    select c1 into v_blob from test where c1=’a';
    dbms_output.put_line(sql%rowcount);
    as_pdf_mini.put_image(v_blob, 50,50,400,300);
    as_pdf_mini.save_pdf (‘mydir’,’a.pdf’);
    end;
    —————————————————-
    After the a.pdf is created but wothout img.  Can you help me to understand what happen? thanks a lot francesco
     

    • Anton Scheffer on

      select c1 into v_blob from test where c1 = ‘a’
      That means that v_blob contains ‘a’ and not a blob/jpg :)

  18. Hi anton,  I attach you only a part of my code ( 400 lines)
    now i try to create a test case,  and i’ll attach you later.
    f.

  19. Hi  Anton, I nee your help to solve this problem. I have a table  with a long row data type (contain jpg ).  I want to insert the image into a pdf.
    My code:
    v_blob blob;
    ..
    Select speall_img  into v_blob from spe_Alleg where rowid = r.riga;
    as_pdf_mini.put_image(v_blob, 10,10,400,300);
    but The plsql return an error:

    ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
    ORA-06512: at line 350

    Can You help me? Thanks a lot Francesco

    • Anton Scheffer on

      @fransesco
      line 350 in as_pdf_mini is not related to put_image, so I doubt that the error is caused by the code you show.

  20. Anton Scheffer on

    @franseco
    If you have a oracle DIRECTORY, you have a place on the filesystem of your oracle database. and if you have on that place a image file you can use the procedure put_image to put that image in your pdf.
      procedure put_image(
        p_dir => ‘yourDirectory’
      , p_file_name => ‘yourImage.jpg’
      , p_x => 100
      , p_y => 400
    );

  21. Hi Anton, I just descovered as_pdf_mini, is a good tools. I try to create a simple pdf , but I want to attach a image from File system.
    I create a oracle DIRECTORY , buy I not understand how use “add_image” function, can yuo help me? thanks Francesco

  22. Is it possible to generate the pdf and then load the blob into a db table?  Have you done this using your as_pdf_mini package?

    • @AJ GOLDEN
      If you look in the code of the plugin you can see a line “t_pdf := as_pdf2.get_pdf;”
      At that point you have the generated PDF in a blob t_pdf. And you can store that blob in the DB.
      For this plugin I used as_pdf2. It’s almost the same as as_pdf_mini, but some procedures added (for different ttf-fonts), some things removed.

  23. I have a question regarding your plugin to generate to pdf in APEX. In the readme you specify to “create a new process based on the plugin” created by as_pdf2.sql.  I do not see how to create a process based on a plug in.  Can you provide instruction for doing that?

  24. Hi Anton,
    It seems like we now know what is happening. The third server where we’re getting the error that I mentioned before, has a verisign security certificate, unlike the other two servers. And we think, that may be causing the error. If you don’t mind me asking, does the as_pdf_mini support this kind of security certificates? the only reason why I ask is because there are other images loaded in the webservice (but not the pdf) and those ones don’t seem to give any trouble.
    Thank you so much again!!!
    Best regards,
    Brenda

  25. Hi Anton,
    Have you ever run into an error like this:
    Error RA-06512: at “SYS.UTL_HTTP”, line 1029 ORA-06512: at “SYS.HTTPURITYPE”, line 70 ORA-06512: at “SOLTRAMUSR.AS_PDF_MINI”, line 1324 ORA-06512: at “WWWUSER.SWGPDFUTIL”, line 665
    It’s just that, I have been generating a PDF in two servers already, and up to now, everything is still fine in those two servers, but now I passed everything into a third one, and when I try to load an image into the PDF with the “put_image” function (that’s line 665), I get this error, and haven’t changed anything from one server to the other.
    This is line 665:
    as_pdf_mini.put_image( p_url =>  lsPathImagenes, p_x => .01, p_y => .01, p_width => 615, p_height => 855);
    I already verified the path, and it is where the image is supposed to be, I checked that the file is there, and it is.
    Ring any bells?
    Thanks in advance,
    Best regards,
    Brenda

    • @Brenda: No, I haven’t seen that before. But I know that on a 11G databases you have to make certain settings before you can make http calls to a url outside the server. Maybe you have to look into that

    • Removing the mod helps a bit, turning pls_integer to number did help too (to my surprise!) . I did try turning the blob into a clob and into a raw, but I got the most from casting it to a varchar2

  26. Anton,
    I think you may have an issues in the following statement:
    step_size := trunc( 16383 / dbms_lob.getchunksize( p_src ) ) * dbms_lob.getchunksize( p_src )
    if chunk size is 32K your step_size will be zero!

    • @Alex I know, but I’ve never seen a database with value higher than 8132, I gues my DBA’s don’t care about performance ;). But the function is fast, is it?

  27. Hi Anton,
    thanks for the great package! I really enjoyed using it and I though that I could also contribute a little bit ;-)
    1. adler32
    The function suffers quite a lot of performance hit due to dbms_lob.substr, when you have PDF with a lot of images it really starts to add up… I did a version which is 6x-10x faster:
     
    function adler32(
    p_src in blob
    ) return varchar2 is
    l_buf_size pls_integer := 8192;
    l_buffer raw(8192);
    s1 pls_integer := 1;
    s2 pls_integer := 0;
    begin
    for i in 1 .. ceil(dbms_lob.getlength(p_src)/l_buf_size)
    loop
    l_buffer := dbms_lob.substr(p_src, l_buf_size, (i-1)*l_buf_size+1);
    for j in 1 .. utl_raw.length(l_buffer)
    loop
    s1 := mod( s1 + utl_raw.cast_to_binary_integer( utl_raw.substr(l_buffer, j, 1) ), 65521 );
    s2 := mod( s2 + s1, 65521);
    end loop;
    end loop;
     
    return to_char( s2, ‘fm0XXX’ ) || to_char( s1, ‘fm0XXX’ );
    end;
     
    2. Repeatedly calling INIT will cause LOB descriptors leaks
    That’s caused by dbms_lob.createtemporary( pdf_doc, true ) since init does not check if pdf_doc was already allocated or not. Also I thought that it would be nice for a package to offer an option to clean up any outstanding LOB descriptors without having to call finish_pdf (i.e. in case of handling exception and freeing resources) so I’ve added two procedures:
     
     
    procedure free_tmp_lob(
    p_blob in out blob
    ) is
    begin
    if ( nvl(dbms_lob.istemporary(p_blob), 0) = 1 )
    then
    if ( dbms_lob.isopen(p_blob) = 1)
    then
    dbms_lob.close(p_blob);
    end if;
    dbms_lob.freetemporary(p_blob);
    end if;
    end;
     
    procedure free_lobs is
    l_n number;
    begin
    l_n := pages_tab.first;
    while ( l_n is not null )
    loop
    free_tmp_lob(pages_tab(l_n));
    l_n := pages_tab.next(l_n);
    end loop;
     
    l_n := images.first;
    while ( l_n is not null )
    loop
    free_tmp_lob(images(l_n).pixels);
    l_n := images.next(l_n);
    end loop;
     
    free_tmp_lob(pdf_doc);
    end;
    Then I’ve added free_lobs call to the beginning of init procedure.
    3. parse_img adler32 call optimization
    parse_img has the following call:

    img.adler32 := nvl( p_adler32
    , adler32( p_blob )
    );
    the problem is that adler32 is going to be called even if p_adler32 is not null (it might be PL/SQL optimizer setting and/or version dependent but though but I didn’t verify that yet) so I’ve rewritten that part as:

    if (p_adler32 is null)
    then
    img.adler32 := adler32( p_blob );
    else
    img.adler32 := p_adler32;
    end if;

    that’s all for now, keep up with the awesome work!
     
     

    • @Alex
      Thanks for the contributions!!! I’ve noticed that the adler32 function was way to slow when I was loading/embedding ttf-fonts (in another version of the package). I’ve settled for this version of the function
      function adler32( p_src in blob )
      return varchar2
      is
      s1 number := 1;
      s2 number := 0;
      step_size number;
      tmp varchar2(32766);
      c65521 constant number := 65521;
      begin
      step_size := trunc( 16383 / dbms_lob.getchunksize( p_src ) ) * dbms_lob.getchunksize( p_src );
      for j in 0 .. trunc( ( dbms_lob.getlength( p_src ) – 1 ) / step_size )
      loop
      tmp := rawtohex( dbms_lob.substr( p_src, step_size, j * step_size + 1 ) );
      for i in 1 .. length( tmp ) / 2
      loop
      s1 := s1 + to_number( substr( tmp, i * 2 – 1, 2 ), ‘xx’ );
      if s1 >= c65521
      then
      s1 := s1 – c65521;
      end if;
      s2 := s2 + s1;
      if s2 >= c65521
      then
      s2 := s2 – c65521;
      end if;
      end loop;
      end loop;
      return to_char( s2, ‘fm0XXX’ ) || to_char( s1, ‘fm0XXX’ );
      end;

  28. hello anton,
    thanks for this solution. how can i publish the result of the procedure as_pdf_mini.save_pdf in my apex-application?
    after the user klick on a button the process start, create the pdf and save this in the directory on the apex-server. now i’ll like to present the result to download for example.
    thanks,
    carsten

    • Anton Scheffer on

      @Carsten
      I don’t know that much of Apex :). But you can always try to use as_pdf_mini.show_pdf instead of save_pdf.

  29. Hi Anton,
    Thanks for all your help! It did work the displaying of the accented vowels, apparently the problem was about something else.
    In the other hand, I wonder if it has happened to you what I’ve seen with my pdf, even though it has been only occasional. Sometimes, when I show it, it first displays a lot of “garbage” in the browser. I’m not 100% sure, but it seems to happen when a session was left in the middle. Have you seen this before?, is there any additional “cleaning” I should do even though from what I saw in your code, the pdf is created as temporary.
    Thank you so much in advance!
    Brenda

    • Anton Scheffer on

      @Brenda
      No I haven’t seen those “garbage”, but I don’t use Apex (and this plugin) that much.

  30. Anton Scheffer on

    @Brenda. The mini version of this package only supports the Windows-1252 characterset. Á, É, Í, Ó, Ú are part of that, so I think you could use them.

  31. Hello Anton,
    I need to print few characters which are part from the extended ASCII table (Á, É, Í, Ó, Ú). In html I could do this going with UTF-8, is there a way I could have these in my PDF using your package?, could I specify UTF-8 encoding? So far, I haven’t had any problem with the smallcaps (á,é,í,ó,ú) but the capital letters show as weird characters.
    Thanks in advance,
    Best regards,
    Brenda

    • Anton Scheffer on

      @Brenda: I’ve made some changes to the package to handle smaller line widths. Please get the latest version if you need it.

  32. Thanks for your response about the images Anton. I greatly appreciate it. It’s weird though, as we are loading the image as url, and if I do the put_image with the url parameter to all pages, it consumes way too much memory… I guess we’ll have to look for alternatives.
    There is one more thing I’d like to ask you…about the rect procedure that is used to build boxes…is there a way to print the line thinner?, I have been trying to give a p_line_width smaller than the default 0.5, but it still gets painted the same thickness.
    Thanks in advance!!!
    Brenda

  33. Thank you so much. How about using HTML? Is there any way to use HTML tags in order to generate the layout of the PDF page?

    • Anton Scheffer on

      No, not even support for HTML tags. You have to build the layout all by yourself.

  34. Hi again,
    Kindly ignore my previous post.Since it was my first time to use utl_file i was lost bit.Is it possible to use template with this package?for example I have a template that I need to fill it with data from APEX.what should I do?Thank you so much in advance
     

  35. Hi,
    Thank you so much.I have a question which is stupid.when i run the package it says invalid directory path?should i run it as sys?what should I do?Thank you in advance

  36. Anton Scheffer on

    @brendaivett
    If you call put_image several times with the same image (the same hash-value actually) only one copy of the image is stored in the PDF. But you have to call put_image several times, it’s not a function which return a pointer or index to the image for later use.
    Anton

  37. Hi Anton,
    If I need to include the same image in different pages. Is there a way to only load a image once but make it visible several times in different pages?
    Thanks in advance,
    Brenda

  38. Can I somehow add another fonts in the package? Just like you did. This is very important for me.
    Please help.

    • Anton Scheffer on

      @miki No, with this (mini) version of the package you can only use the 14 standard PDF fonts. Loading, parsing and using other (ttf)-fonts would more than double the size of the package. I have that working on my Windows machine with an UTF-8 database, but it isn’t code I will publish. Far to much trouble with people wich use a database with a different characterset and a different OS.

  39. Hi Anton.
    You have made a very good job, I want use your package. But missing two characters which are used in my language. How to replace two characters with my two.

    • Anton Scheffer on

      @miki For others characters you need other fonts. And using other fonts isn’t possible with this package.

  40. Anton Scheffer on

    Use one of the overloaded procedures put_image. The package header contains an example.

    procedure put_image(
        p_dir in varchar2
      , p_file_name in varchar2
      , p_x in number
      , p_y in number
      , p_width in number := null
      , p_height in number := null
      );

      procedure put_image(
        p_url in varchar2
      , p_x in number
      , p_y in number
      , p_width in number := null
      , p_height in number := null
      );

      procedure put_image(
        p_img in blob
      , p_x in number
      , p_y in number
      , p_width in number := null
      , p_height in number := null
      );

  41. Anton Scheffer on

    @António I don’t do any image conversion into varchar. Image 5 shows the output from an refcursor, build with the procedure refcursor2pdf, see the package header

  42. Hi,
    Can you tell me where you made the image conversion into the varchar? (image 5)
    Regards,
    António

  43. Mikhail Goncharov on

    Hi,
    Is it possible for me to use the embedded-pdf plugin listed above to create the pdf export for the pl-sql region ?
    How can I do it ?
    Thanks
    Mikhail
     

  44. How would you propose running a ref cursor or a straight cursor against your process?
    I just wrote a small little anonymous block:
    declare
    cursor cur_Invent is
    SELECT ITEM,
    DESC1 Description,
    TO_CHAR(PRICE5,’$999.99′) Price
    FROM TEST_INVENTORY
    ORDER BY Desc1;

    begin
    as_pdf_mini.init;

    FOR Invent_rec in cur_Invent
    LOOP
    as_pdf_mini.write(Invent_rec.Item||’     ‘);
    as_pdf_mini.write(Invent_rec.Description||’  ‘);
    as_pdf_mini.write(Invent_rec.Price);
    END LOOP ;
    as_pdf_mini.save_pdf;
    End;
    and It seemed to hang..
    Can you have some alignment of columns using the write function or do I format that myself?  Also new lines do we add a new line character to get an end of line written?
    Thank you,

    Tony Miller
    LuvMuffin Software
    (281) 871-0950
     

    • Anton Scheffer on

      @Tony, The package is the mini-version of a more fullblown package, so the functionality is basic. The package header contains an example procedure refcursor2pdf to display a refcursor. And see the source of my APEX plugin, http://www.apex-plugin.com/oracle-apex-plugins/region-plugin/embedded-pdf_65.html, for a much better example of that procedure.
      You can use the parameter p_x of the write procedure to do some column formating, that will work better than appending some spaces behind the text (which might cause the hanging of your code, I will look into that some day). A newline character written to write forces a newline in the PDF.

  45. Very nice, I used it for bargraph-reports. I am not familliar with pdf, but ,  – is it hard to draw a line which is not vertical or horizontal. I would like to draw polygons for charting.

    • Anton Scheffer on

      Sorry, no direct support for polygons. You can use the procedure add2page to add PDF-commands to the generated PDF, but that’s not easy :)

  46. @Ino. Yes, I have looked at that one. But I decided to build my own, just for the fun. And mine’s much better of course :)