PTC ALD in Arbortext Styler > Components of Documents and Templates > Content Types > Graphical Content
  
Graphical Content
Introduction
Two types of graphic are supported in PTC Arbortext Layout Developer — raster graphics and vector graphics. They behave slightly differently from each other and have different properties. It is also possible to display graphical content inline.
Refer to Graphics for additional information about graphic types.
Raster Graphic Content
PTC Arbortext Layout Developer supports the following raster graphic formats:
JPG
TIFF
BMP
GIF
PNG
EPS
GEM
PICT
PDF — this is a special case. It is possible to select a page from a PDF file and use it as a raster graphic. When outputting to PDF (the only output supported with this graphic type) the source PDF page is included in the output file.
The fContent object includes the importRaster() method for loading a raster graphic. The method returns an fRaster object (a .rg tag).
This sample code loads the raster graphic myFile.jpg into a tag named myGraphic:
var path = new fPath("D:/myFile.jpg");
var graphic;
graphic = template.content.getRaster("myGraphic");
if (!graphic) template.content.importRaster("myGraphic", path, fRaster.FT_JPEG, true);
This example creates an fPath object to provide the location path for the graphic, which is usually gathered from an href attribute). The code tests if the named graphic tag exists, and if it does not exist the raster is imported.
The importRaster() method takes a number of parameters:
"myGraphic" — the name of the PTC Arbortext Layout Developer graphic tag to create
path — the location path for the graphic file to be imported, an fPath object
fRaster.FT_JPEG — the type of file to load. The file types are described in the Formatting Object Model (FOM) under the RasterFileType constant for the fRaster object.
If the file type is unknown, use the file type fRaster.FT_AUTO to activate an auto mode. PTC Arbortext Layout Developer examines the file to derive its type.
true — indicates that the graphic should be linked to the document, the recommended setting. If false, the graphic is loaded into the document.
page (not used in this example) — indicates the page from a PDF that should be imported, if importing PDF pages as graphics.
Refer to fContent for information.
Refer to fContent in the Formatting Object Model Reference for information.
When the graphic is loaded, properties from the fRaster object are available, for example:
height and width — the graphic’s dimensions
Height and width information is particularly useful for calculating if there is sufficient space on the page for the graphic before displaying it.
filename and graphicType — source filename and graphic type
bitsPerPixel — resolution information
hasClipPath — whether a clipping path has been provided with the graphic from Photoshop.
Clipping paths can be used to wrap text content around the path in the graphic.
Properties that indicate whether the graphic has been manipulated using PTC Arbortext Layout Developer’s menu system (rarely used)
Refer to fRaster for information.
Refer to fRaster in the Formatting Object Model Reference for information.
Vector Graphic Content
PTC Arbortext Layout Developer provides support for a number of vector graphic formats, including SVG and CGM. PTC Arbortext Layout Developer also has a vector graphic drawing tool which can be used to create simple graphics.
The fContent object includes an importGraphic() method for importing vector graphics.
This example code imports the vector graphic file myFile.svg into the tag named myGraphic:
var path = new fPath("D:/myFile.svg");
var graphic;
graphic = template.content.getGraphic("myGraphic");
if (!graphic) template.content.importGraphic("myGraphic", path, fGraphic.FT_SVG, true);
The parameters follow the same pattern as for the importRaster() method. The only exception is that the file type is listed in the GraphicFileType constant for the fGraphic object.
Displaying Graphical Content Inline
With PTC Arbortext Layout Developer, graphical content can be both displayed inline and attached to a frame. Inline display is more common in Arbortext Styler-based output. The fFormatting object includes an addImage() method that allows both vector and raster graphics to be displayed inline.
This example code displays the raster graphic tag myGraphic inline:
var graphic = template.content.getRaster("myGraphic");
formatting.addImage(graphic, false, fFormatting.SCALE_FIT, "", fFormatting.SCALE_PRESERVE, "");
The graphic variable assignment could also use the fContent.getGraphic() method to display a vector graphic instead of a raster graphic.
The parameters used in the example for the addImage() method are as follows:
graphic — the name of the raster or vector tag to be displayed
false — indicates that the graphic should be displayed as a separate block. If true, the graphic is displayed on the same line as the text around it.
fFormatting.Scale_FIT — how to scale in the x axis. See the description of the ImageScale constant for scaling options.
""— the size to use, specified by an fLength object, if a size type scale option is requested in the previous parameter, for example SCALE_ABSOLUTE
The parameter does not need a value in this example.
fFormatting.SCALE_PRESERVE — how to scale in the y axis. See the description of the ImageScale constant for scaling options.
"" — the y-scale size, as for the x-scale size
The parameter does not need a value in this example.
There are other parameters for the method that should be considered advanced settings. Refer to fContent for information.
There are other parameters for the method that should be considered advanced settings. Refer to fContent in the Formatting Object Model Reference for information.
The horizontal and vertical scaling options defined in the ImageScale constant for the fFormatting object are:
SCALE_NONE / No scaling — keep the image at 100%
SCALE_PRESERVE / Preserve aspect ratio — if one axis has scaling, the shape of the image is retained
SCALE_FIT / Scale to fit — ensure that the graphic sizes to fit the measure available, either by shrinking or expanding
SCALE_DOT / Dot size —scale the image using the specified dot size
SCALE_ABSOLUTE / Absolute — scale to a particular size, using a valid length
SCALE_PERCENT / Percent — scale to a percentage of its original size, using a percentage value
SCALE_SHRINK / Shrink — scale the graphic if it too large for the given size available
SCALE_ENLARGE / Enlarge — scale the graphic if it too small for the given size available
Barcode/QR Codes
PTC Arbortext Layout Developer supports barcodes and other scannable objects, for example QR codes. You can use PTC ALD edited source in your Arbortext Styler stylesheet to configure a graphic object to display a code of the required type, with the requisite values. The code can then be included in PDF output generated by the PTC ALD engine.
Formatting Object Model items support this feature:
fBarcode object — represents the barcode configuration
fContent.createBarcode() method — creates the fGraphic tag that holds the barcode graphic
Refer to Generating Barcodes and QR Codes for information.