2. Can I generate full Rich Text
Oracle Reports with the PDF Generator in
Oracle Forms?
The Sferyx PDF Generator for
Oracle Forms is a new product which resolves exactly this problem - it
allows a fully formatted rich text generation of Oracle Reports in PDF
from Oracle forms - it is capable of rendering everything inside the
report - images, text, tables, lists - anything done automatically and
exported in PDF. It works with all existing oracle reports and oracle
forms and is quite simple to use. Furthermore you can use it to generate
any kind of PDF documents directly from Oracle Forms using the available
API.
3. How can I integrate the PDF Generator in
Oracle Forms?
As any other java bean is integrated in
Oracle Forms designer. Place the jar file in the designer's classpath
and it will be automatically detected by the Oracle Forms Designer. You
can add it after that easily as a bean area.
- copy the PDFGenerator.jar file in
the <ORACLE_HOME>/forms/java directory
- edit your /forms/server/formsweb.cfg
file to add the PDFGenerator.jar as follows:
# Forms applet archive setting for JInitiator
archive_jini=f90all_jinit.jar,PDFGenerator.jar
# Forms applet archive setting for Microsoft Internet Explorer
native JVM
archive_ie=f90all.cab,PDFGenerator.jar
# Forms applet archive setting for other clients (Sun Java Plugin,
Appletviewer, etc)
archive=f90all.jar,PDFGenerator.jar
- open the
PDFGenerator-reports-example.fmb
module (Oracle Forms module)
- compile all and run the module
- Into the Oracle Forms Visual
designer insert a Bean area and set the implementation property to
sferyx.administration.pdfgenerator.PDFGeneratorOracleBean
4. How to generate a report with the PDF
Generator in Oracle Forms?
You can generate easily
full rich text reports from existing Oracle Reports by following the
examples and the guidelines below:
The PDFGenerator gives you
the possibility to create PDF files from existing reports by
supplying the report URL as a parameter to the PDFGenerator which
has been embedded inside an sample Oracle Form.
Declare
hArgs FBEAN.ARGLIST;
Begin
hArgs:=FBEAN.CREATE_ARGLIST;
FBEAN.ADD_ARG(hArgs,'http://'||host||'/reports/rwservlet?'||report_string);
FBEAN.ADD_ARG(hArgs,'Letter');
FBEAN.ADD_ARG(hArgs,'PORTRAIT');
FBean.Invoke('PDFGENERATOR_AREA',1,'generatePDFFromReport',hArgs);
please consult the available examples
in the folder "examples/oracleforms" for major details.
There are the following cases
when generating reports with the PDFGenerator:
- If your report contains
HTML fields then you can preserve their formatting in the
following way:
1) In the Oracle Reports
Builder, for the field containing the HTML code you should set the
property "Contains HTML Tags" to "NO"
2) In the Oracle Reports
Builder, for the field containing the HTML code you should set the
property "CSS Class Name" - "sferyx_pdf_generator" - please write
this as you see it in small case without trailing spaces.
After that you can
generate the report as specified in the examples.
- If your report contains
HTML fields which span through multiple pages then you can
preserve the formatting in the following way:
1) Use the method
generatePDFFromURL instead of generatePDFFromReport
The argument format for this method is this: generatePDFFromURL(URL,
"c:/test1.pdf","Letter","PORTRAIT"); or one of its variations
2) At the end of the URL
pointing to the report, you should append the parameter &pagesize=8.5x512
so it becomes something like
'http://'||host||'/reports/rwservlet?'||report_string||'&pagesize=8.5x512'.
3) Use the following method to discard the eventual blank pages
public void setDiscardEmptyPages(boolean discard) - Specifies to
automatically discard all pages that do not contain text and are
practically blank pages.
If you experience
difficulties in configuring the parameters specified above, do not
hesitate to contact
support@sferyx.com for further help.
If you need major
flexibility and control over the PDF generation you can consult the
various methods available below in order to construct the necessary
content and PDF files dynamically.
5.
Available methods accessible directly from the
sferyx.administration.pdfgenerator.PDFGeneratorOracleBean - you should use the same
rules for accessing those methods as described above in the OracleForms
PL/SQL script examples:
public void
generatePDF(java.lang.String sourceURL, java.lang.String
destinationFile) -Generates a pdf file from given URL and saves
it to a given filename using default paper size and orientation
publiv void
generatePDFFromContent(java.lang.String content, java.lang.String
destinationFile, java.lang.String standardPageFormat,
java.lang.String orinetation) - Generates a pdf file from given
html/text content and saves it to a given filename, using paper size
and paper orientation such as LANDSCAPE or PORTRAIT
public void
generatePDFFromReport(java.lang.String sourceURL, java.lang.String
standardPageFormat, java.lang.String orinetation) - Generates a
pdf file from given URL and saves it to temporary file showing the
ready PDF document into the available PDF viewer
public void
generatePDFFromURL(java.lang.String sourceURL, java.lang.String
destinationFile, java.lang.String standardPageFormat,
java.lang.String orinetation) - Generates a pdf file from given
URL and saves it to a given filename using paper size and
orientation
public void
generatePDFFromRTFURL(String sourceURL, String destinationFile,String
standardPageFormat, String orientation) - Generates pdf
automatically for given URL source containing Rich Text Format RTF file.
It will generate the file using the given standard page format string
such as "A4", "Letter" etc. and and save the file to the given File and
page oriantation such as "Portrait" or "Landscape". You can also set the
page margins using the method setMarginsForStandardPageFormat
public void generatePDFFromDocxURL(String sourceURL, String
destinationFile,String standardPageFormat, String orientation) -
Generates pdf automatically for given URL source containing a MS Word
Docx file. It will generate the file using the given standard page
format string such as "A4", "Letter" etc. and and save the file to the
given File and page oriantation such as "Portrait" or "Landscape". You
can also set the page margins using the method
setMarginsForStandardPageFormat
public void
addReportParameter(java.lang.String name, java.lang.String value)
- Adds parameters to be used for generation of the report - this
method can be used multiple times to add multiple parameters. Please
note that this is persistent and once added the parameters will be
used until cleared. See clearReportParameters method.
public void
clearReportParameters() - Clears all the report parameters set previously using
addReportParameter.
public void
openContentBuffer() - Opens the new content buffer for inserting
content inside the PDF Generator. This should be used in conjunction
with closeBufferAndGeneratePDF() and appendContentToContentBuffer(String
content). This methods are very useful in environments where long
content strings cannot be inserted at once due to some limitations as
happens for example in Oracle Forms.
public void
appendContentToContentBuffer(String content) - Appends new string to
existing content buffer. This should be used in conjunction with
openContentBuffer() and closeBufferAndGeneratePDF(). This methods are
very useful in environments where long content strings cannot be
inserted at once due to some limitations as happens for example in
Oracle Forms.
public void
closeBufferAndGeneratePDF(String destinationFile,String
standardPageFormat, String orinetation) - Closes the existing
content buffer and inserts its content inside the PDF Generator. This
should be used in conjunction with openContentBuffer() and
appendContentToContentBuffer(String content). This methods are very
useful in environments where long content strings cannot be inserted at
once due to some limitations as happens for example in Oracle Forms.
OR
public String
closeBufferAndGenerateTempPDFFile(String standardPageFormat, String
orinetation) - Closes the existing content buffer and inserts its
content inside the PDF Generator and generates a temporary file where
the PDF file is saved - the name of the temp file is returned as a
result from the method. This should be used in conjunction with
openContentBuffer() and appendContentToContentBuffer(String content).
This methods are very useful in environments where long content strings
cannot be inserted at once due to some limitations as happens for
example in Oracle Forms. See supplied examples in the users manual.
public void
setScaleToFitWidth(boolean scale) - Indicates whether to rescale the
page in order to fit the given PageFormat - the default is true
public void
setOpenGeneratedFileInPDFViewer(boolean show) - Indicates whether to
automatically open the default PDF Viewer and show the generated file or
not. The default is true
public void
setMarginsForStandardPageFormat(int top, int bottom, int left, int
right) - Sets the margins to be used when the page format is set
using the standard string like "A4" or "Letter" - this values will not
be considered it PageFormat object is used to set the page format
public void
setCharset(String charSet) - Sets the character set to be used. The default one is
supporting the majority of the western latin languages. If you would
like to support any other language you must specify "utf-8" as character
set to be used - this will cause also all the TTF fonts used inside the
document to be embedded into the resulting PDF file.
public void
setHeader(String content) -
Generates the header for each page in the document. The parameter
content can be any plain text or HTML string - it will be parsed and
rendered as a header on the pages. You can includes any HTML element
such as images, tables, colors etc. Keep in mind to adjust the top
margin in order to make enough room for the header if necessary.
public
void setFooter(String content) -
Generates the footer for each page in the document. The parameter
content can be any plain text or HTML string - it will be parsed and
rendered as a footer on the pages. You can includes any HTML element
such as images, tables, colors etc. Keep in mind to adjust the bottom
margin in order to make enough room for the footer if necessary.
public
void setDiscardEmptyPages(boolean discard)
- Specifies to automatically discard all
pages that do not contain text and are practically a blank pages.
public
void setGeneratePageNumbers(boolean generate,String text)
- Generates page numbers for each page in
the document. The parameter content can be any plain text or HTML string
- it will be parsed and rendered practically as footer in the pages and
will parse the special directive "@#SferyxPDFGenerator-PageNumber#@" in
order to place the page number inside the custom formatting. You can
includes any HTML element such as images, tables, colors etc. Keep in
mind to adjust the top margin in order to make enough room for the page
numbering if necessary.
Example: <p align=center style="padding-top:30px;border-top:1px solid
#0000FF;"><font face="arial" color="blue">Page: @#SferyxPDFGenerator-PageNumber#@</font></p>
public void
setTTFFontFolderName(java.lang.String folderName)
- sets the absolute path to the folder which
contains the TrueType fonts to be used when generatiing the PDF
documents. Please make sure that this feature is enabled by setting the
character set to UTF-8
public
java.lang.String getTTFFontFolderName() -
returns the name of the True Type fonts if
previously set. Otherwise it will return null and for the generation of
the PDF files will be used the system font folders.
void
setDoNotBreakListsAcrossPages(boolean disablebreak)
- if set to true, the PDFGenerator will try
to not break list elements when page break is encountered if the list is
not longer than the page height.
void
setDoNotBreakTablesAcrossPages(boolean disablebreak)
- if set to true, the PDFGenerator will try
to not break tables when page break is encountered if the table is not
longer than the page height.
java.lang.String closeBufferAndGeneratePDFSynchronously(java.lang.String
destinationFile, java.lang.String standardPageFormat, java.lang.String
orinetation) - closes the
existing content buffer and inserts its content inside the PDF
Generator.
boolean
isDoNotBreakListsAcrossPages() -
returns whether the PDFGenerator should not allow to the lists to break
across the pages
boolean
isDoNotBreakTablesAcrossPages() -
returns whether the PDFGenerator should not allow to the tables to break
across the pages
Here is also some
simple example on how to use the content buffer for generating large PDF
documents in Oracle Forms:
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'openContenBuffer');
FBEAN.ADD_ARG(hArgs, :block_control.description1);
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'appendContentToContentBuffer',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
FBEAN.ADD_ARG(hArgs, :block_control.description2);
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'appendContentToContentBuffer',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
FBEAN.ADD_ARG(hArgs, :block_control.description3);
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'appendContentToContentBuffer',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
FBEAN.ADD_ARG(hArgs, :block_control.description4);
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'appendContentToContentBuffer',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
FBEAN.ADD_ARG(hArgs, :block_control.description5);
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'appendContentToContentBuffer',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
FBEAN.ADD_ARG(hArgs, 'c:\test.pdf');
FBEAN.ADD_ARG(hArgs,'Letter');
FBEAN.ADD_ARG(hArgs,'PORTRAIT');
FBEAN.INVOKE('block_control.PDFGenerator', 1, 'closeBufferAndGeneratePDF',
hArgs);
FBEAN.CLEAR_ARGLIST(hArgs);
6.
Data transfer from CLOB to
PDFGenerator and generation of the pdf file
This example uses some
table names and columns which you will need to adapt the query in the
example to your environment or create the same tables
================INSERT INTO PDFGENERATOR FROM CLOB AND GENERATE THE PDF
FILE===================
DECLARE
bean varchar2(200):='PDFGENERATOR_AREA';
t_id number(20):=1;
hArgs FBEAN.ARGLIST;
parts number(20);
part varchar2(32500);
part_size number(20) := 1000;
body_length number(20);
BEGIN
hArgs := FBEAN.CREATE_ARGLIST;
-- Init PDFGenerator Buffer
FBean.Invoke(bean,1,'openContentBuffer');
-- Get CLOB content lenght
select nvl(dbms_lob.getlength(ASSUMPTION_DESC),0) into body_length
from EPM_CONTRACT_CONS where EMP_NO = t_id;
if body_length > 0 then
-- Get Length and number of the parts
select trunc(dbms_lob.getlength(ASSUMPTION_DESC)/ part_size) +1
into parts from EPM_CONTRACT_CONS where EMP_NO = t_id;
for i in 1..parts loop
select dbms_lob.substr(ASSUMPTION_DESC,part_size,((i-1)*part_size)+1)
into part from EPM_CONTRACT_CONS where EMP_NO = t_id;
hArgs := FBEAN.CREATE_ARGLIST;
FBEAN.ADD_ARG(hArgs,part);
FBean.Invoke(bean,1,'appendContentToContentBuffer',hArgs);
end loop;
end if;
-- Populate the PDFGenerator and generate the file
FBean.CLEAR_ARGLIST(hArgs);
FBean.ADD_ARG(hArgs, 'c:\test-new.pdf');
FBean.ADD_ARG(hArgs,'Letter');
FBean.ADD_ARG(hArgs,'PORTRAIT');
FBean.Invoke(bean, 1, 'closeBufferAndGeneratePDF', hArgs);
END;
7. Screen illustrating the setting of the
properties inside the Oracle Forms builder
You can note on the screenshot
below the bean implementation property of the Bean Area is set to
sferyx.administration.pdfgenerator.PDFGeneratorOracleBean: