PDFinclude Documentation
PDFinclude Documentation
Version 2.4
Documentation
Prepared by:
PRO-SYS Consultants Ltd.
Gordon Campbell
November 12, 2003
This document is included as a component of the PDFinclude
Open-Source initiative. PDFinclude has been submitted to the
FreeFrameWork project and therefore is now available as per the
FreeFrameWork license.
PDFinclude is a stand-alone component that defines a toolset of Progress functions that aid in the
output of a PDF file … without having to generate a separate text file first.
PDF files can be read by PDF viewers such as Adobe Reader and PDFView.
The PDF file format is fast becoming an industry-standard for electronic document viewing. The
PDF format allows for documents that can be accessed by a broad range of hardware and
software devices (including PDAs and Internet browsers).
PDFinclude utilizes Progress code that is compliant with versions 8 and 9 of the Progress 4GL.
Consistency By using the PDF file format, you can present a representation of the
output file in a consistent manner. Use the same PDF file across
multiple devices, platforms and/or software packages.
Easy Implementation Since PDFinclude is written in Progress the ability to implement into
your existing (or new) code is easy and seamless. No external calls
are required to third-party products (such as a Perl script).
Secure Report Output The PDF file format is a secure format that cannot be easily changed
therefore sensitive reports can be distributed to users without the
worry of them changing reported material.
Report Viewer Supplied Since PDF is becoming an industry-standard file format, many
document viewers already exist (such as Adobe’s Acrobat Reader).
This reduces your development effort by not having to create a
separate Report Viewer.
Due to the complexity of the PDF specification and our requirement of having PDF easy to
implement, building a PDF document with PDFinclude involves two different planes … or Spaces
as they are called within the PDF specification. The two spaces are the Text Space and the
Graphic Space. Each of the spaces are defined further in preceding sections but the following
items outline the basic space functions.
Text Space: The Text Space allows you to manipulate and control the where and how text
will appear on the document. The Text Space starts on the top-left hand
corner of the page and moves across and downward. Similar to how current
reports are developed with Progress.
Graphic Space: The Graphic Space allows you to manipulate and control the drawing of non-
textual object such as JPEG Images, Rectangles, Lines, etc. The Graphic
Space start at the bottom-left corner of the page and move up and across.
By manipulating and controlling the Spaces, you can create elegant documents that are directly
derived within your Progress application.
Before using of the following procedures or functions, you must add “{ pdf_inc.i }” to your Progress
program.
As of PDFinclude Version 2, pdf_inc.i now accepts an argument. The argument allows you to
specify whether you want to add the pdf_inc.p as a SUPER procedure or not. The following table
outlines the possible options.
Description:
This procedure closes the identified PDF stream and generates the PDF document that was
identified in the pdf_new procedure.
pdf_Encrypt
Description:
This procedure allows you to encrypt a generated PDF document. The call to this procedure can
occur anywhere between the appropriate pdf_new and pdf_close procedures.
This procedure call integrates with PDFpsp.w (another external procedure). PDFpsp.w uses a
commercial product called Pretty Safe PDF (PSP) from PDFlib GmbH. The PSP product can be
downloaded from www.pdflib.com. PRO-SYS has is a reseller of all PDFlib GmbH products and
we offer PEG members a discount. For more information go to www.epro-sys.com. The discounts
will only be applied by PRO-SYS. PDFlib GmbH will not honour the discounts, so orders must be
directed to PRO-SYS Consultants Ltd.
Parameter Description
Stream Name Must be a valid Stream Name as created in the procedure – see calls to
‘pdf_new’ to identify valid stream names.
Master Password The Master Password must be a maximum of 32 characters. A ‘blank’
password is valid.
Access List The Access list can be ‘blank’ or a comma-delimited list of access
prevention rights. If ‘blank’, the document has full access rights (default).
If ‘non-blank’, then only specific items will be allowed when the document
is viewed. The following table outlines the valid entries for the comma-
delimited list:
Code Description
Encryption Key This value can either be 40 or 128. This value represents the length of the
Length Encryption Key (in bits). 128 Bit encryption is currently the strongest
encryption available.
Encryption Mode PSP can be run via a few different options. The options available vary by
Operating System. The following table outlines the values and the
Operating System that they can be used with.
Mode OS Description
Silent Encryption
pdf_load_font
This procedure allows you to load and embed external fonts for later use. You can ‘use’ a font by
using the pdf_set_font procedure.
The DIF file is optional and is only used if you want to remap some of the characters. The DIF file
should have a format similar to the following:
65 /SF100000
66 /SF110000
67 /SF010000
68 /SF030000
69 /SF040000
70 /SF080000
71 /SF090000
72 /SF060000
73 /SF070000
74 /SF050000
75 /SF430000
76 /SF240000
77 /SF510000
78 /SF520000
79 /SF390000
80 /SF220000
81 /SF210000
82 /SF250000
83 /SF500000
84 /SF490000
85 /SF380000
86 /SF280000
87 /SF270000
88 /SF260000
89 /SF360000
90 /SF370000
The first entry represents the character to replace and the second entry represents the Postscript
name of character to replace it with. The Postscript character names can be found at:
http://partners.adobe.com/asn/tech/type/opentype/appendices/wgl4.jsp
pdf_Font_Diff
Description:
pdf_load_image
Description:
This procedure allows you to load and embed and external JEPG image. You can ‘use’ the
image by using the pdf_place_image procedure. Currently, only JPEG images can be loaded
using this procedure.
pdf_line
Description:
This procedure allows you to draw a line from a given starting point to a specified end point. You
can determine the color of the line by using the pdf_stroke_color procedure. You can also change
the appearance of the line by using the pdf_set_dash procedure.
pdf_link
Parameters: Stream Name as Character - Stream name as identified in pdf_new
From X as Integer - A non-zero integer value representing the
X axis starting point
From Y as Integer - A non-zero integer value representing the
Y axis starting point
Link Width as Integer - How wide should the link boundry be?
Link Height as Integer - How high should the link boundry be?
Link Text as Character - Text to appear when link is hovered over
Text Red as Integer - Red value of RGB Colour
Text Green as Integer - Green value of RGB Colour
Text Blue as Integer - Blue value of RGB Colour
Link Border as Integer - Non-negative integer for the border width
Link Style as Character - Display style of link
Description:
This procedure allows you to place a rectangular link boundry into a PDF document. This can be
useful when used with linking a Customer ID to another document that lists all Customer Invoices.
The link boundry could also be placed around an image (such as a logo image) that once clicked,
could redirect someone to your corporate webpage.
pdf_move_to
Description:
This procedure allows you to dynamically change Graphic State locations within the PDF stream.
pdf_new
Description:
This procedure initiates a new PDF stream to create with PDFinclude. The stream name must be
unique and is used by most all other PDFinclude functions and procedures. By adding a stream
name to each of the functions and procedures, we allow you to create multiple (unlimited) PDF
documents from within a single Progress procedure.
When creating a new stream, this procedure loads the PDF Base 14 fonts (a defined set of fonts
including Courier, Helvetica, etc) plus it includes setup of the following default parameters:
Orientation Portrait
PaperType LETTER
PageWidth 612
PageHeight 792
Render 0
TextX 0
TextY 0
Font Courier
FontSize 10
GraphicX 0
GraphicY 0
VerticalSpace 10
LeftMargin 10
TopMargin 50
pdf_new_page
Description:
This procedure initiates a creates a new PDF page to write output to. It also resets the current
TextX, TextY, GraphicX and GraphicY parameters.
Note: The Progress default paging is not used, as is the Header, Footer, Page-Top, Page-
Bottom, Page-Number, and Line-Counter options. Using PDFinclude requires that you control all
output.
pdf_place_image
Parameters: Stream Name as Character - Stream name as identified in pdf_new
Image Name as Character - Valid Image name as pre-loaded with
pdf_load_image function
Graphic Column as Integer - Non-zero integer value identifying the
columnar location to begin drawing the image
Graphic Row as Integer - Non-zero integer value identifying the row
location to begin drawing the image
Width as Integer - Non-zero integer value representing the
width to render the image at
Height as Integer - Non-zero integer value representing the
height to render the image at
Description:
This procedure places a previously loaded image onto the current PDF page at the specified
location.
pdf_rect
Description:
This procedure draws a rectangle onto the current PDF page at the specified location using the
specified width and height.
pdf_reset_all
Parameters: None
Sample Call: RUN pdf_reset_all.
Description:
This procedure clears all PDF content for all defined PDF streams.
Description:
This procedure clears all PDF content for the named PDF stream.
pdf_rgb
Sample Call: RUN pdf_rgb (“Spdf”, “pdf_text_color”, “0x006466”) /* Hex Teal Green*/
RUN pdf_rgb (“Spdf”, “pdf_text_color”, “000100102”) /* Decimal Teal Green*/
Description:
This procedure accepts a six digit Hex RGB color code (preceded by ‘0x’, or ‘#’, format
RRGGBB), or a Nine digit decimal RGB color code (format RRRGGGBBB) and converts it into the
three PDF RGB colors. It then runs the Target Procedure, passing in these three PDF colors.
pdf_set_BottomMargin
Description:
This procedure allows you to set the height of the Bottom Margin. As soon as the Text Y location
goes greater than the Bottom Margin then a new PDF page is created. This is useful for
formatting a document as it ensures that you don’t run text to the bottom of the PDF page.
This procedure is also used in conjunction with the PageFooter functionality (explained
elsewhere). That is, if a PageFooter is defined and the Text Y location is greater than the Bottom
Margin, then the PageFooter is automatically output to the PDF document.
pdf_set_dash
Description:
This procedure allows you to take a solid line (or rectangle) and adjust it to look like a dashed line.
The On/Off parameter options allows you to define the appearance of the dashed line. You may
want to have one short line appear (eg: On=1) then have a fairly large space where the line
doesn’t appear at all (eg: Off=10).
pdf_set_font
Description:
This procedure allows you to set how the following text will be displayed. All text following this
procedure will appear using the set font until the Font is set back to another font.
The following table defines the names of the PDF Base14 Fonts.
Note: Only 12 are defined right now. We still need to add the WingDings and Symbol Fonts.
Description:
This procedure allows you to set values that help you define attributes about the PDF document
itself. The following table outlines the settable attributes:
Attribute Description
pdf_set_LeftMargin
Description:
This procedure allows you to set the number of points that the document will be indented from the
left-hand edge of the pages boundaries (identified by Page Height and Page Width).
pdf_set_Orientation
Description:
This procedure allows you to define how the page should be displayed … upright (Portrait) or
lengthwise (landscape). This value can be set before or after the Page Height or Page Width has
been set but must be set before the call to the pdf_new_page procedure.
pdf_set_PageHeight
Description:
This procedure allows you to define how tall (or wide if using Landscape orientation) the page
should be. This value can be set before or after the Page Width or Orientation has been set but
must be set before the call to the pdf_new_page procedure. As soon as this procedure is used,
the Paper Type is set to “CUSTOM”.
pdf_set_PageWidth
Description:
This procedure allows you to define how wide (or tall if using Landscape orientation) the page
should be. This value can be set before or after the Page Height or Orientation has been set but
must be set before the call to the pdf_new_page function. As soon as this procedure is used, the
Paper Type is set to “CUSTOM”.
pdf_set_PaperType
Description:
A0 2380 3368
A1 1684 2380
A2 1190 1684
A3 842 1190
A4 595 842
A5 421 595
A6 297 421
B5 501 709
LETTER 612 792
LEGAL 612 1008
LEDGER 1224 792
The Widths and Heights identified in the preceding table are based on the Portrait orientation. If
you were to change the Orientation to ‘Landscape’ then the Width and Height columns would be
reversed.
pdf_set_parameter
Description:
This procedure allows you to set parameters associated with the specified PDF stream. The
following table outlines the valid parameter names and potential values (please note that with
using 40-bit encryption only certain parameters are useful or work).
Compress The parameter allows you to specify that you want to compress the data
streams. Compression occurs before encryption.
Possible Values: 40
pdf_set_TextBlue
Description:
Possible Values: Any realistic decimal value between 0.0 and 1.0.
pdf_set_TextGreen
Description:
This procedure allows you to individually change the Green value of the current RGB colour
scheme. That is, if you had previously set the font to Black (eg: Red=0, Blue=0, Green=0) then
you can easily change it to use green text by running the sample call (as above). Then you can
easily set it back to black by using ‘RUN pdf_set_TextGreen (“Spdf”,0.0).
Possible Values: Any realistic decimal value between 0.0 and 1.0.
pdf_set_TextRed
Description:
This procedure allows you to individually change the Red value of the current RGB colour
scheme. That is, if you had previously set the font to Black (eg: Red=0, Blue=0, Green=0) then
you can easily change it to use red text by running the sample call (as above). Then you can
easily set it back to black by using ‘RUN pdf_set_TextRed (“Spdf”,0.0)’.
Possible Values: Any realistic decimal value between 0.0 and 1.0.
pdf_set_TopMargin
This procedure allows you to set the number of points that the document will be indented from the
top edge of the pages boundries (identified by Page Height and Page Width)
pdf_set_VerticalSpace
Description:
This procedure allows you to set the number of points that represents the vertical spacing of lines.
A value of 12 is typical for Portrait oriented documents while 10 is fairly common for Landscape
oriented documents.
pdf_skip
Description:
This procedure will skip to the next line in the Text Space. This also updates the current TextX
and TextY attributes for the stream.
pdf_skipn
Description:
This procedure will skip n number of lines in the Text Space. This also updates the current TextX
and TextY attributes for the stream. This saves you calling pdf_skip multiple times.
pdf_stroke_color
Description:
This procedure allows you to change the color PDF objects that are stroked. These include
stroked text (see pdf_text_render), lines, and rectangle borders.
pdf_stroke_fill
Description:
This procedure allows you to change the color PDF objects that are filled. These include filled text
(see pdf_text_render), and rectangles.
pdf_text
Description:
This procedure allows you to place the passed text string at the current TextX and TextY Text
Space points.
pdf_text_at
Description:
This procedure allows you to place the passed text string at column 60 (determined by current
PointSize * passed Column Value) on the current Text row (TextX).
Note: The column value entered here is determined by the actual row that you would like to see
the text appear beginning at. That is, assuming a PointSize of 10, instead of entering 600 to have
the text begin at Column 60, just enter 60.
pdf_text_boxed_xy
Description:
This procedure allows you to specifically place the passed text string at the passed Row and
Column. A box will be placed around the text.
Note: The column and row values passed to this function should represent the actual PDF points.
That is , unlike pdf_text_at, if you want to have the text appear at point 600 then enter 600 (not
60).
pdf_text_center
Description:
pdf_text_color
Description:
This procedure allows you to set the color that the following text displays should appear in.
pdf_text_render
Description:
This procedure allows you to define how the text will be rendered. There are four possible values
and they are outlined below.
0 Fill Text
1 Stroke Text
2 Fill, then Stroke Text
3 Neither Fill nor Stroke Text (invisible)
pdf_text_rotate
This procedure will set the rotation angle for displaying text in. This must be run before you
display the text you want rotated.
pdf_text_to
Description:
This procedure allows you to place the passed text string right-aligned to the specified column
(determined by current PointSize * passed Column Value) on the current Text row (TextX).
Note: The column value entered here is determined by the actual row that you would like to see
the text appear beginning at. That is, assuming a PointSize of 10, instead of entering 600 to have
the text begin at Column 60, just enter 60.
pdf_text_xy
Description:
This procedure allows you to specifically place the passed text string at the passed Row and
Column.
Note: The column and row values passed to this procedure should represent the actual PDF
points. That is , unlike pdf_text_at, if you want to have the text appear at point 600 then enter 600
(not 60).
pdf_Watermark
Description:
This procedure allows you to place a text watermark into the PDF document. The watermark will
appear only on the Page where it is issued, so if you want to have it appear on all pages ensure
that the command is reissued whenever a new page is issued.
pdf_Wrap_Text
Description:
This procedure allows you to place text into the PDF document within a from/to column location.
If the text is longer than the from/to location then it will automatically wrap the text to the next line
and place the remaining text within the same from/to location as the previous line. This is useful
when printing character fields that have been input via an Editor widget.
2017-03-10 PDFinclude V2.4 Documentation 30
4. Function List
pdf_Angle
Returns: Integer
Sample Call: pdf_Angle (“Spdf”)
Description:
This function returns the currently set angle that is being used for the Text Rotation.
pdf_BottomMargin
Returns: Integer
Sample Call: pdf_BottomMargin (“Spdf”)
Description:
This function returns the currently set value of the PDF pages Bottom Margin.
pdf_Font
Returns: Character
Sample Call: pdf_Font (“Spdf”)
Description:
This function returns the currently selected font that is being used to display text.
pdf_get_info
Description:
This function returns the value of the specified Document Information attribute.
Possible attributes are listed in the table below:
Attribute Description
pdf_get_NumFittingChars
Returns: Integer
Sample Call: pdf_get_NumFittingChars
(“Spdf”,
“This is my text example”,
10).
Description:
This function returns the index of the last character that will fit into the specified width. It does this
by summing each characters AFM width (as specified in the tt_pdf_font.font_width array) and
comparing with the required width (converted into these same units).
pdf_get_parameter
Description:
This function returns the value of the specified Document parameter. For a list of valid document
parameters see the ‘pdf_set_parameter’ procedure.
pdf_get_wrap_length
Description:
You can use the function to see how long a piece of text WOULD be if you were to wrap it.
pdf_GraphicX
Returns: Integer
Sample Call: pdf_GraphicX (“Spdf”)
Description:
This function returns the value of the current X (Column) location of the Graphic State.
pdf_GraphicY
Returns: Integer
Sample Call: pdf_GraphicY (“Spdf”)
Description:
This function returns the value of the current Y (Column) location of the Graphic State.
pdf_GraphicY
Returns: Integer
Sample Call: pdf_GraphicY (“Spdf”)
Description:
This function returns the value of the current Y (Column) location of the Graphic State.
pdf_ImageDim
Arguments: Stream Name as Character - Stream name as identified in pdf_new
Image Name as Character - Image name as defined with a
pdf_load_image
Dimenstion Type as Character - Either HEIGHT or WIDTH
Returns: Integer
Sample Call: pdf_ImageDim (“Spdf”,”Logo”,”HEIGHT”)
Description:
This function returns the value of the Image Dimension that was requested with Dimension Type
input parameter. This is useful because when you load the image you don’t know the Image
Width or Height. With this function you can determine either.
pdf_Orientation
Returns: Character
Sample Call: pdf_Orientation (“Spdf”)
Description:
This function returns the value of the Orientation parameter. The Orientation parameter is used to
define how the page appears.
pdf_Page
Returns: Integer
Sample Call: pdf_Page (“Spdf”)
Description:
This function returns the value of the current Page parameter. The Page parameter is
incremented after every call to a pdf_new_page.
pdf_PageFooter
Returns: Logical
Sample Call: pdf_PageFooter (“Spdf”, THIS-PROCEDURE:HANDLE, “PageFooter”)
This function notified PDFinclude that the calling report procedure has a Page Footer procedure
associated with it. If this has been set (with a non-blank value) then whenever a text element is to
be displayed below the Bottom Margin (set by pdf_set_BottomMarging) this procedure (eg:
PageFooter) will be called.
pdf_PageHeader
Returns: Logical
Sample Call: pdf_PageHeader (“Spdf”, THIS-PROCEDURE:HANDLE, “PageHeader”)
Description:
This function notified PDFinclude that the calling report procedure has a Page Header procedure
associated with it. If this has been set (with a non-blank value) then on each call to
pdf_new_page this procedure (eg: PageHeader) will be called.
pdf_PageHeight
Returns: Integer
Sample Call: pdf_PageHeight (“Spdf”)
Description:
This function returns the value of the current Page Height parameter. The Page Height parameter
is used to determine the page boundaries. The Page Height parameter can either be set directly
by using pdf_set_PageHeight or indirectly by calling pdf_PaperType.
pdf_PageWidth
Returns: Integer
Sample Call: pdf_PageWidth (“Spdf”)
Description:
This function returns the value of the current Page Width parameter. The Page Width parameter
is used to determine the page boundaries. The Page Width parameter can either be set directly
by using pdf_set_PageWidth or indirectly by calling pdf_PaperType.
pdf_PaperType
Returns: Character
Sample Call: pdf_PaperType (“Spdf”)
Description:
This function returns the value of the current Paper Type parameter. The Paper Type parameter
is used to determine the page boundaries. The Paper Type parameter is set by calling
pdf_set_parameter and selecting a valid Paper Type or by calling pdf_set_PageHeight or
pdf_set_PageWidth. Calling either of the two latter functions will set the Paper Type to
‘CUSTOM’.
Valid Paper Types are:
A0 2380 3368
A1 1684 2380
A2 1190 1684
A3 842 1190
A4 595 842
A5 421 595
A6 297 421
B5 501 709
LETTER 612 792
LEGAL 612 1008
LEDGER 1224 792
The Widths and Heights identified in the preceding table are based on the Portrait orientation. If
you were to change the Orientation to ‘Landscape’ then the Width and Height columns would be
reversed.
pdf_PointSize
Returns: Integer
Sample Call: pdf_PointSize (“Spdf”)
Description:
pdf_Render
Returns: Integer
Sample Call: pdf_Render (“Spdf”)
Description:
This function returns the value of the current Text Rendering parameter. The Test Rendering
parameter is used to determine how the text will be drawn on the PDF page. The Text Rendering
parameter is set by calling the pdf_Text_Render function.
The following table outline the possible values for the Text Rendering parameter:
0 Fill Text
1 Stroke Text
2 Fill, then Stroke Text
3 Neither Fill nor Stroke Text (invisible)
pdf_text_width
Returns: Integer
Sample Call: pdf_text_width (“Spdf”,”End of Report”)
Description:
This function allows you to determine the length (in points) of the passed text string. The width is
calculated as follows:
width = (LENGTH(text value) * individual character lengths / 1000) * pdf_PointSize(PDF Stream)
The individual character lengths may differ for each character within a given font. The
accumulation of the total character widths divided by 1000 then multiplied by the current font Point
Size. This function is useful when used in conjunction with the pdf_text_boxed_xy function
(allowing you to determine how wide the box around the text should be).
pdf_TextBlue
Returns: Decimal
Sample Call: pdf_TextBlue (“Spdf”)
Description:
This function allows you to determine what the current Blue value of the current RGB setting is.
pdf_TextGreen
Returns: Decimal
Sample Call: pdf_TextGreen (“Spdf”)
Description:
This function allows you to determine what the current Green value of the current RGB setting is.
pdf_TextRed
Returns: Decimal
Sample Call: pdf_TextRed (“Spdf”)
Description:
This function allows you to determine what the current Red value of the current RGB setting is.
pdf_TextX
Returns: Integer
Sample Call: pdf_TextX(“Spdf”)
Description:
This function returns the current X (Column) location within the Text Space.
pdf_TextY
Returns: Integer
Sample Call: pdf_TextY (“Spdf”)
Description:
This function returns the current Y (Row) location within the Text Space.
Returns: Character
Sample Call: pdf_TotalPages (“Spdf”)
Description:
This function allows you to include the Total Number of Pages for the document directly into your
report. For instance, if you wanted to have 'Page n of x' as your Page footer then you can
implement this with pdf_TotalPages(streamname).
pdf_TopMargin
Returns: Integer
Sample Call: pdf_TopMargin (“Spdf”)
Description:
pdf_VerticalSpace
Returns: Integer
Sample Call: pdf_VerticalSpace (“Spdf”)
Description:
This function returns the current point size for the Vertical Space. The Vertical Space is used to
define the spacing between lines.
5. Internal Procedures and Functions
This section outlines the other procedures and functions that are used within PDFinclude. These
procedure and functions should not be used within programs as they may cause issues when
developing a PDF document.
Page Headers appear whenever a call to pdf_new_page is issued. The Page Header is
generated before anything else can be included in the PDF content of the page, ensuring that the
Page Header content actually appears at the top of the page … unless you’ve used an element
that uses specific X/Y positioning (eg: pdf_text_xy or pdf_place_image), then that element can be
placed anywhere on the current page (useful if you wanted a watermark to appear on a page).
Page Footers appear only if you have set the Bottom Margin of the page (using
pdf_set_BottomMargin). If any text elements (except X/Y positional text elements) are going to be
displayed below the Bottom Margin setting, then the Page Footer code block is run and a call to
pdf_new_page is issued .. to automatically increment the PDF paging. Ensure that when you call
pdf_set_BottomMargin you set the value to something that will allow your Footer to appear
correctly. That is, if you set the value to low (say 10) you may not get a page footer, or if your
footer included graphic elements those elements may overlay some of the text.
To create Page Footers and Page Headers for a report, you need to create code blocks
(procedures) in your program that will generate the appropriate output. For example, the following
procedure illustrates a PageFooter:
PROCEDURE PageFooter:
/*------------------------------------------------------------------------------
Purpose: Procedure to Print Page Footer -- on all pages.
------------------------------------------------------------------------------*/
/* Display a Sample Watermark on every page */
RUN pdf_watermark ("Spdf","Customer List","Courier-Bold",34,.87,.87,.87,175,500).
END. /* PageFooter */
But this code won’t be run unless we communicate this procedure to PDFinclude. To do that you
need to make the appropriate call. The two calls (functions) that notify PDfinclude that you have
included headers and footers in your report are:
This function call lets PDFinclude know that we have a footer procedure in our calling program.
7. How to Implement Compression
The ability to compress data streams was implemented in version 2.3 of PDFinclude.
PDFinclude uses the zlib library to implement Flate compression. Zlib is a free open-source
project and the binaries (or source) for many operating systems can be found at www.zlib.net.
2. Open the file zlibbind.p Progress procedure in the PDFinclude download. Change the
zlib pre-processor to point to the appropriate DLL or Shared Library object.
3. Add the following command to each of the PDF documents that you wish to compress:
This statement can be run anytime between the calls to ‘pdf_new’ and ‘pdf_close’. If you
happen to run the statement multiple times before ‘pdf_close’, then the last call will be
used to determine whether compression is to be used or not.
4. Run your code and you will see a reduction in your PDF filesize.
Currently, PDFinclude does not compress images. You can expect this in future versions.
PDFinclude uses the external binaries and DLL or Shared Library objects to perform the
encryption. Initially the encryption was implemented using pure 4GL components but the
encryption was way too slow. For example, it would take almost 20 seconds to encrypt the simple
‘Hello World’ example …. a simple one-page Customer Listing was taking almost 50 seconds.
These timings were unacceptable, hence the requirement for external utilities.
If you are on a *NIX OS then you will need to compile the rc4.c object into a Shared Library (I
currently don’t have instructions on how to do that …. so if someone actually reads this then
please forward the instructions to me at [email protected] - TIA).
2. Edit pdfencrypt.p and modify the pre-processor MD5LIB to point to the appropriate md5
routine.
4. Add the following command to each of the PDF documents that you wish to encrypt:
This statement can be run anytime between the calls to ‘pdf_new’ and ‘pdf_close’. If you
happen to run the statement multiple times before ‘pdf_close’, then the last call will be
used to determine whether encryption is to be used or not.
You can also set the Allow*, UserPassword and/or MasterPassword document
parameters to determine the permissions (see ‘pdf_set_parameter’ procedure
documentation for more info) associated with the PDF document.
5. Run your procedures and see the encrypted (or protected) PDF document.
The following sample produces a minimal PDF document. The output file is included in the Zipped
download and is called hello.pdf.
{ ./pdf_inc.i }
RUN pdf_new ("Spdf","c:\sports2000\PDFinc\hello.pdf").
RUN pdf_new_page("Spdf").
RUN pdf_text ("Spdf", "Hello World").
RUN pdf_close("Spdf").
{ ./pdf_inc.i }
RUN pdf_new ("Spdf","c:\sports2000\PDFinc\hello-encrypt.pdf").
RUN pdf_new_page("Spdf").
RUN pdf_set_parameter("Spdf",”Encrypt”,”TRUE”).
RUN pdf_set_parameter("Spdf",”Compress”,”TRUE”).
RUN pdf_text ("Spdf", "Hello World").
RUN pdf_close("Spdf").
The following sample produces a PDF document displaying the different type of Text options
available. The output file is included in the Zipped download and is called text.pdf.
{ ./pdf_inc.i }
RUN pdf_set_font("Spdf","Courier",14.0).
RUN pdf_text_xy ("Spdf","This is text placed using XY coordinates",100,500).
RUN pdf_set_font("Spdf","Courier",10.0).
RUN pdf_close("Spdf").
This sample produces a Customer Listing that illustrates how to create a basic PDF report. The
output file is included in the Zipped download and is called custlist.pdf.
{ ./pdf_inc.i }
Vlines = Vlines + 2.
END. /* Last-of State */
END.
RUN end_of_report.
RUN pdf_close("Spdf").
PROCEDURE new_page:
RUN pdf_new_page("Spdf").
Vpage = Vpage + 1.
PROCEDURE page_footer:
RUN pdf_skip ("Spdf").
RUN pdf_set_dash ("Spdf",1,0).
RUN pdf_line ("Spdf", 0, pdf_TextY("Spdf") - 5, pdf_PageWidth("Spdf") - 20 , pdf_TextY("Spdf") - 5, 2).
RUN pdf_skip ("Spdf").
RUN pdf_skip ("Spdf").
RUN pdf_text_to ("Spdf","Page: " + STRING(Vpage), 97).
END. /* page_footer */
PROCEDURE end_of_report:
RUN page_footer.
/* end of custlist.p */
This sample produces a Item Listing that illustrates how you can control the output of a fairly
custom PDF report. The output file is included in the Zipped download and is called itemlist.pdf.
{ ./pdf_inc.i }
END.
RUN pdf_close("Spdf").
PROCEDURE display_item_info:
/* Draw Smaller box (white filled) to contain Item Picture (when avail) */
RUN pdf_stroke_fill("Spdf",1.0,1.0,1.0).
RUN pdf_rect ("Spdf", pdf_LeftMargin("Spdf") + 10, Vrow + 10, pdf_LeftMargin("Spdf") + 100 , 90).
RUN pdf_text_color("Spdf",.0,.0,.0).
/* Display the Product Number as a Bar Code */
RUN pdf_set_font("Spdf","Code39",14.0).
RUN pdf_text_xy ("Spdf",STRING(item.ItemNuM,"999999999"), 140, Vrow + 60).
PROCEDURE new_page:
RUN pdf_new_page("Spdf").
PROCEDURE load_cat_desc:
DEFINE VARIABLE L_cat AS CHARACTER NO-UNDO.
L_extent = 1.
DO L_Loop = 1 TO NUM-ENTRIES(L_cat," "):
IF (LENGTH(Vcat-desc[L_extent]) + LENGTH(ENTRY(L_loop,L_cat," ")) + 1) > 40
THEN DO:
IF L_extent = 4 THEN LEAVE.
L_extent = L_extent + 1.
END.
/* end of itemlist.p */
As previously mentioned, you need to be legally responsible when embedding True Type Font
files into any documents. Most fonts are embeddable but not distributable. In order to ascertain
whether you can legally embed the TTF file you should download the Extended Font Viewer from
Microsoft.
The Extended Font Viewer can be obtained via the following link:
http://www.microsoft.com/typography/property/property.htm?fname=%20&fsize=
Once installed you can right-click on a TTF file, select the ‘Properties’ option and the following
screen (or very similar – dependant on Windows version) will appear.
Click on the “Embedding” tab. Here you will see the license options available for the Font file.
Basically, if it says that you have ‘Restricted License Embedding” then you cannot legally embed
the font file.
PRO-SYS is not legally responsible for any actions you take with embedding font files into your
PDF file.
Appendix B – Creating AFM File
The Adobe Font Metrics (AFM) file is used by PDFinclude to determine how the glyphs (or
characters) should appear when displayed by a PDF viewer (such as Adobe Acrobat).
The AFM file stores information such as glyph widths, is the font italicized, glyphs defined etc.
PDFinclude does not generate the AFM file for you. Instead you must resort to using a free utility
called ‘ttf2pt1’. This utility will read a TTF file and generate the AFM file.
To download ‘ttf2pt1’ go to the following link:
http://ttf2pt1.sourceforge.net/
The utility is written in C and must be compiled into binary executable format on whichever
platform you are running. PRO-SYS has a Windows binary executable copy available for free
distribution. Contact mailto:[email protected]?subject=ttf2pt1 to obtain the download.
Note: PRO-SYS was unable to compile the 3.4.0 version but we were able to compile the 3.3.5
version.
Once installed and compiled, the process to create the AFM file is very simple. The following
command can be used as an example.
ttf2pt1 –A \windows\fonts\arial.ttf arial
The ‘–A’ is important. This option actually indicates to ttfpt1 that it must output an AFM file.
You may wish to read the documentation that comes with the download for a further
understanding of what ttf2pt1 is capable of.
PRO-SYS does not resell ttf2pt1 as a component of the PDFinclude package. If you have another
tool that generates AFM files then by all means use it.
PRO-SYS does not support ttf2pt1 and is not legally responsible for anything related to the utility.