Skip to main content

 Tutorials

Task-driven tutorials and recipes for PageSeeder

How to create document collections from a template

Skills requiredXML
Time required (minutes)30
Intended audienceDeveloper
DifficultyEasy
CategoryDocument

Objective

Through the PageSeeder interface, document templates allow users to create single documents. This tutorial explains how developers can use a process script to have a document template create an entire collection of linked documents.

Use Case

Applications for this functionality are multi-document reports or publications that require components such as front matter, body and back matter.

Prerequisites

To complete this tutorial requires:

  • Administrator access to a PageSeeder server.
  • Knowledge of how to create projects, groups, folders and documents in PageSeeder.

Tutorial

Setup projects, groups and documents

  1. Create a project called “example”.
  2. In this project, create groups called “template” and “publication”.
  3. In “example-template” create a folder called “templates”.
  4. In “templates” create a folder called “publication1”.
  5. In “publication1” create one document with a type of “references”.
  6. From the “references” document, create and link a few documents with a type of “default” (these will form the template for one document collection).
  7. Repeat tasks 4-6  for a folder called “publication2”.

Setup process script

  1. In the “example” project and go the Project dashboard
  2. Select Publish scripts from the menu
    Project menu – Publish scripts
  3. Click Configure scripts for group/folder/document.
  4. Replace the content with the following XML and click Save at the bottom (the <value> elements define your list of templates, so would need to be updated if you add or rename template folders).
    <publishing>
      <action type="process">
        <source type="folder" />
        <target name="create-collection">
          <description>Create document collection</description>
          <param name="template-name"
                 label="Template"
                 type="select">
            <!-- THE FOLLOWING VALUES SHOULD BE
                 MODIFIED FOR EACH SPECIFIC PROJECT --> 
            <value>publication1</value>
            <value>publication2</value>
          </param>
          <param name="collection-name"
                 label="New collection name"
                 type="text" />
        </target>
      </action>
    </publishing>
    
  5. Return to the Publish scripts page and click Refresh
  6. Click create next to the “create-collection” target.
  7. Replace the content with the following XML and click Save (modify the template-folder property for a different project).
<project name="folder-process"
         xmlns:ps="antlib:com.pageseeder.publishapi.ant">

  <target name="create-collection"
          description="Create document collection">

    <!-- Folder containing the templates
         (MODIFY FOR SPECIFIC PROJECT) -->
    <property name="template-folder"
              value="/ps/example/template/templates" />

    <!-- load PageSeeder config properties -->
    <ps:config />

    <!-- create working folders -->
    <property name="download"
              value="${ps.config.default.working}/download" />
    <property name="process"
              value="${ps.config.default.working}/process" />
    <mkdir dir="${download}"/>
    <mkdir dir="${process}"/>

    <!-- export template documents -->
    <ps:export src="${template-folder}/${ps.param.template-name}"
               dest="${download}" />

    <!-- remove docids to avoid clashes -->
    <ps:process src="${download}"
                dest="${process}"
                processed="false"
                preservesrc="true">
      <strip documentinfo="docid" />
    </ps:process>

    <!-- zip files to preserve folder structure on upload -->
    <zip destfile="${ps.config.default.working}/upload.zip"
         basedir="${process}" />

    <!-- upload template documents to new location -->
    <script language="javascript">
 var name = project.getProperty("ps.param.collection-name");
 project.setProperty("foldername",name.toLowerCase().replaceAll(" ", "_"));
    </script>

    <ps:upload group="${ps.config.default.group.name}"
               folder="${ps.config.default.uri.path.no.group}/${foldername}"
               unzip="true">
      <fileset file="${ps.config.default.working}/upload.zip" />
    </ps:upload>

    <echo>Creation successful!</echo>
  </target>
</project>

Create a collection

  1. In PageSeeder go to the 'example-publication' group and click on Documents.
  2. Next to the 'documents' folder select Process  by mousing over the actions icon at right (this is where the document collection will be created, so you could select any folder).
  3. Select a Template from the drop down list and type a New collection name (e.g. My new publication)
  4. Click the Process button and wait until 'Creation successful!' appears.
  5. Click Close, then click on the documents folder and you should see the folder for your new collection with the documents from the template inside it.

Folder process dialog – Create document collection

Created on , last edited on

Available tutorials