Batch print pdf documents from Oracle database using mod plsql and wpg_docload
There are several utilities on the market that enable you to batch print documents that are written to a directory. These tools have the disadvantage that you need to install a third party tool on the client PC or server.
This html document describes how to batch print pdf documents using wpg_docload.download_file. The documents are printed directly through the browser of the client PC.
Actually, the trick is real simple. You can only call wpg_docload.download_file once in a window. To have multiple files to be downloaded in a single event, you have to open a window for each document.
Table that holds the documents
create table my_pdf_documents
( id number not null
, document blob
) tablespace my_space;
create public synonym my_pdf_documents for my_pdf_documents;
Pl/sql package specification that performs the batch print
create or replace package batch_print is
--
procedure p_batch_print_pdf;
procedure p_download_file(p_id number);
--
end batch_print;
/
Pl/sql package body that performs the batch print
create or replace package body batch_print is
----------------------------
-- Batch print pdf documents
----------------------------
procedure p_batch_print_pdf
-- Add arguments for the where clause
is
begin
--
htp.p('Printing ...');
--
-- Loop over all the documents that have to be printed
--
-- Add arguments for where clause
for r_pdf in ( select * from my_pdf_documents )
loop
--
-- Print document in a new window
--
htp.p('<SCRIPT LANGUAGE="JavaScript">');
htp.p('DocloadWin = window.open("batch_print.p_download_file'
||'?p_id='||r_pdf.id||'"'
||',"DocloadWin"'
||',"width=150,height=150,left=10000");'
);
-- left = 10000 makes window invisible
htp.p('</script>');
--
--
end loop;
--
-- Close parent window if call to p_batch_print_pdf was done in new window.
--
htp.p('<SCRIPT LANGUAGE="JavaScript">');
htp.p(' this.close();');
htp.p('</script>');
--
end p_batch_print_pdf;
--------------------------------------------------------
-- Download a single document to browser uusing mimetype
-- application/x-pdfprint
--------------------------------------------------------
procedure p_download_file
( p_id number
) is
begin
--
for r_pdf in ( select document from my_pdf_documents where id = p_id )
loop
--
owa_util.mime_header('application/x-pdfprint',false);
htp.p('Content-Length: ' || dbms_lob.getlength(r_pdf.document));
owa_util.http_header_close;
--
wpg_docload.download_file
( r_pdf.document
);
--
end loop;
--
end p_download_file;
--
end batch_print;
/
create public synonym batch_print for batch_print;
grant execute on batch_print to public;
Registry settings to send the document to the printer
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/x-pdfprint]
"Extension"=".pdp"
[HKEY_CLASSES_ROOT\.pdp]
@="pdpfile"
"Content Type"="application/x-pdfprint"
[HKEY_CLASSES_ROOT\pdpfile]
@="Internet PDF Print App"
"EditFlags"=dword:00010000
[HKEY_CLASSES_ROOT\pdpfile\Shell]
@=""
[HKEY_CLASSES_ROOT\pdpfile\Shell\Open]
"EditFlags"=dword:00010000
[HKEY_CLASSES_ROOT\pdpfile\Shell\Open\command]
@="\"C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe\" /p /h \"%1\""
Example of the test link
http://server/pls/dad/batch_print.p_batch_print_pdf