WTDocument Coversheet Customization
This section describes suggested ways to change the out-of-the-box behavior and layout of PDF coversheets, which can be inserted in document representation upon release or publication. The default layout of coversheet is as follows:
This layout is controlled by a template file. The template is simple html with specialized markups; these markups will be replaced with actual values generated by its generator classes. The out-of-the-box template for DOCX files (doc_cover.tpl) appears as follows:
The $(COMMON_HEADER), $(DOCUMENT_TITLE), $(COMMON_APPROVE_INFO) and $(COMMON_REVIEW_INFO) entries in the above template are markups. Each markup is associated with its generator class. The generator class will replace that markup with its value in the coversheet. The basis of the coversheet template mechanism is the concept of generators (text parsers), which browse through the template and find all these markups. A markup is constructed as ${<marker name>}. Each generator follows the same procedure recursively:
The generator takes a persistable object and template file (content) as input parameters.
The generator finds all markups inside the template file.
For every markup found, create mapping: key = markup name, value = default value (defined inside the generator class).
The generator reads the template configuration, and searches to see if there is a generator definition for particular markup name. This definition contains the class name for the generator and the template file.
If such a generator is found inside the configuration file, creates (using reflection methods) an instance of that generator class, and repeats the procedure.
If no generator is found, check to see if the current generator gave any replacement for marker (an attribute extracted from the current persistable object) – if so, create mapping: key = markup name, value = data extracted from persistable object.
Replace all markups with mapped values.
There is also list of predefined markups which can be used in coversheet creation.
Coversheet Customization Example
Coversheets can be customized in several ways; some examples are provided here, with examples.
In the first example, a new template (CustomTemplate.tpl) is created and registered, along with its generator, in template.properties.xconf for the file type DOCX. The coversheet can be customized by modifying the template file (which is actually a modified html file). Create a new template file (CustomTemplate.tpl) with the following content:
<html>
<head>
<title></title>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1">
</head>
<body style="font-size:11px; color:#000000; font-family: Helvetica, Verdana,
Arial, sans-serif;">
<p align=center><span style='font-size:20.0pt;color:#E36C0A'
>Coversheet Customization Example</span></p>
<table style="border-collapse: collapse; width: 908px; height: 100%">
<tr>
<td height="5%">&nbsp;</td>
</tr>
<tr>
<td height="55%" align="left" valign="bottom">&nbsp;</td>
</tr>
</table>
</body>
</html>
Configure this template in codebase\com\ptc\coversheet\template.properties.xconf as follows for DOCX files:
<Property name="com.ptc.coversheet.DOCX.template"
default="$(wt.codebase.location)/com/ptc/coversheet/basic/tpl/doc/CustomTemplate.tpl"/>
The resulting coversheet appears as follows
You can insert the image into a coversheet using the <img></img> tag. A Base64–encoded data of the image can be inserted into the coversheet. (Conversion of an image to Base64–encoded data can be done using any online tool). Include the image data using the <img src="data:image/${IMAGE_TYPE};base64,${IMAGE_DATA}"/> tag.
The following image (ptc.jpg) will be inserted into the coversheet.
Convert ptc.jpg into Base64, and add an img tag in the template as follows:
The resulting coversheet looks like this:
You can use the out-of-the-box markups to extract the document info and put that in coversheet. The following example uses the HEADER_NUMBER, HEADER_VERSION and HEADER_DATE markups.
The resulting coversheet looks like this:
The following table lists the available out-of-the-box markups.
Markup Name
Example
LIFECYCLESTATE
Released
AUTHOR
Anyuser
DOC_BUSINESSTYPE
WTDocument
DOC_HASHANGINGCHANGE
FALSE
DOC_MODIFYTIMESTAMP
1/28/2023
ISTDOC_HASVARIANCE
FALSE
CONTEXT_CREATOR
Site, Administrator
HEADER_TITLE
9
DOC_TYPEINFOWTDOCUMENT
wt.doc.WTDocumentTypeInfo
DOC_FORMATNAME
Microsoft Office Word 2007 document
REVISIONINFO
A
DOC_CREATETIMESTAMP
1/28/2023 10:34:15 AM IST
DOC_OBJECTID
OR:wt.doc.WTDocument:146024
DOCUMENT_TYPE
Document
ADAPTER_NAME
doc2pv
DOC_HASPENDINGCHANGE
FALSE
DOC_CREATORFULLNAME
Demo, User
CONTEXT
GOLF_CART
TYPE
Document
COMPANY
PTC
HEADER_VERSION
A.2
NUMBER_OF_WORD
#
LAST_AUTHOR
Anyuser
NUMBER_OF_BYTES
11705
DOC_VERSIONINFO
A
DOC_LIFECYCLEBASIC
TRUE
OBID
VR:wt.doc.WTDocument:108012:213217369-1345475722121-2595331-54-183-21-130@i4950.ptcnet.ptc.com
VERSIONINFO
A.2
DOC_DOCTYPE
Document
TOTAL_EDITING_TIME
0
APPLICATION_NAME
Microsoft Office Word
SECURITY
0
HEADER_NUMBER
21
REVISION_NUMBER
3
DOC_QUALIFIEDIDENTIFIER
A.2
DOC_NUMBER
21
DOC_ORGANIZATIONNAME
Demo Organization
DOC_LIFECYCLESTATE
Released
NUMBER_OF_PAGES
1
CONTEXT_TEMPLATE
Demo Product
DOCUMENT_NUMBER
21
DOC_ITERATIONDISPLAYIDENTIFIER
A.2
SOURCE_FILE_NAME
9.docx
DOC_CONTAINERNAME
GOLF_CART
DOC_LIFECYCLENAME
Basic
CONTEXT_CREATE_TIMESTAMP_ATTRFORMAT=UTC
ORGANIZATION
Demo Organization
LAST_SAVE_TIME
12/24/2023
DOC_TEMPLATED
FALSE
DOC_MODIFIERNAME
demo
URL
http://i4950.ptcnet.ptc.com/Windchill/servlet/WindchillAuthGW/wt.content.ContentHttp/viewContent/9.docx?u8&HttpOperationItem=wt.content.ApplicationData%3A146026&ContentHolder=wt.doc.WTDocument%3A146024&originalFileName=9.docx&forceDownload=true
DOC_NAME
9
CONTEXT_LAST_MODIFIED_TIMESTAMP_ATTRFORMAT=UTC
DOCUMENT_TITLE
9
HEADER_TITLE
9
HEADER_NUMBER
21
HEADER_VERSION
A.2
HEADER_DATE
12/28/2012
NUMBER_OF_CHARACTERS_(WITH_SPACES)
You can also define a new template, generator, and markup to fetch the required information from the persistable object and insert it in the coversheet. The following example defines UPLOADED_FROM_PATH to query UploadedFromPath of the primary content of the document, and registers it in template.properties.xconf.
<Property name="com.ptc.coversheet.UPLOADED_FROM_PATH.class" default=
"com.ptc.coversheet.basic.UploadedFromPathGenerator"/>
<Property name="com.ptc.coversheet.UPLOADED_FROM_PATH.template" default=
"$(wt.codebase.location)/com/ptc/coversheet/basic/tpl/doc/UploadedFromPath.tpl"/>
Define the new template (UploadedFromPath.tpl) for UPLOADED_FROM_PATH:
<tr>
<td>
Uploaded from path = ${UPLOAD_PATH}
</td>
</tr>
Next, define the generator class (UploadedFromPathGenerator.java) for UPLOADED_FROM_PATH as shown below. It should be derived from the abstract generator class and should implement the extractPersistableInfo method; should extract information from the persistable object; and should insert that information in the map as a key-value pair.
package com.ptc.coversheet.basic;

import java.beans.PropertyVetoException;
import org.apache.log4j.Logger;
import wt.content.ApplicationData;
import wt.content.ContentHolder;
import wt.content.ContentItem;
import wt.content.FormatContentHolder;
import wt.doc.WTDocument;
import wt.fc.Persistable;
import wt.util.WTException;

import com.ptc.coversheet.Generator;

/**
* UploadedFromPathGenerator, which retrieves information of Persistable, which are related
* to cover sheet template (title);
* @author Donna Designer (ddesigner@ptc.com)
*
*/
public class UploadedFromPathGenerator extends Generator {
private static Logger logger = Logger.getLogger(CoverGenerator.class);

/**
* Mark-up name which will be replaced by Persistable
*/
private static final String UPLOAD_PATH = "UPLOAD_PATH";

/**
* Generator constructor, only invokes super constructor;
* @param templatePath - direct path to template file;
*/
public UploadedFromPathGenerator(String templatePath) {
super(templatePath);
}

@Override
protected void extractPersistableInfo(Persistable p) {

logger.debug("executing getPersistableInfo(Persistable p) @ " + getClass());
logger.debug("Input parameter (Persistable): " + p);

String uploadedFilepath = "";
if(p instanceof WTDocument) {
WTDocument doc = (WTDocument) p;
try {
ContentHolder ch = (wt.content.ContentHolder)wt.content.ContentHelper.service.getContents
((wt.content.ContentHolder)doc);
ContentItem item = wt.content.ContentHelper.getPrimary( (FormatContentHolder) ch );
ApplicationData ap = (wt.content.ApplicationData) item;
uploadedFilepath = ap.getUploadedFromPath();
logger.debug("Uploaded From Path: " + uploadedFilepath);

} catch (WTException e) {
e.printStackTrace();
} catch (PropertyVetoException e) {
e.printStackTrace();
}

localParametersMap.put(UPLOAD_PATH, uploadedFilepath);
globalParametersMap.put(UPLOAD_PATH, uploadedFilepath);
}
}
}
The CustomTemplate.tpl registered DOCX file appears as follows:
<html>
<head>
<title></title>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1">
</head>

<body style="font-size:11px; color:#000000; font-family: Helvetica, Verdana,
Arial, sans-serif;">
<p align=center><span style='font-size:20.0pt;color:#E36C0A'>
Coversheet Customization Example</span></p>
<table style="border-collapse: collapse; width: 908px;">
<tr>
<td>
Insert Image: <br> <img src="data:image/JPG;base64,/9j/4A……//2Q=="/>
</td>
<td>
Using OOTB markups: <br>
Document Number: ${HEADER_NUMBER} <br>
Document Version: ${HEADER_VERSION} <br>
Document Date: ${HEADER_DATE} <br>
</td>
</tr>
<tr>
<td>
<br> With new template and generator: <br>
${UPLOADED_FROM_PATH} <br>
</td>
</tr>
</table>
</body>
</html>
The configured coversheet appears as:
You can also customize the format and content of coversheets in various ways, such as changing or reformatting the template, inserting images, using out-of-the-box markups; and by creating new templates, associated generators, and markups.
这对您有帮助吗?