Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 986
Product
WordWriter
Version
all
Title
Generating multiple documents in one Word file
Problem
Is it possible to generate multiple documents in one Word file using WordWriter, with one document per page?
Solution

Using a repeat block in your template in conjunction with a page break will allow you to generate one document per page. A common example of this is a form letter, where each page contains a standard letter with a different name and address. Each page would be populated with a different row from the DataSource.

Note: For WordWriter v2, the Enterprise Edition is required to populate repeat blocks.

To create a template with repeating pages, follow the procedure outlined below.

Compose the content of the template

Compose your document, adding merge fields wherever you want data to be filled in at run-time from the database (for example a person's name and address).

Additional info in documentation:
Merge Fields in WordWriter Windows
Merge Fields in WordWriter Java

Add a page break

In order for each document to be on a new page, you need a page break in your template. We recommend adding a page break to the beginning of your first paragraph, in the following manner:

  1. Right click anywhere within the first paragraph of your template and choose Paragraph from the context menu.
    OR
    Left click anywhere within the first paragraph and choose Paragraph from the Format menu.
  2. Choose the Line and Page Breaks tab.
  3. Check the "Page break before" box.

Using this technique, Word is smart enough to not put an extra page at the beginning of your document, but will apply the page break when the paragraph is repeated.

An alternate option is to add a page break at the end your document. You would do this by choosing "Break" from the "Insert" menu and selecting "Page Break". The downside to this is that you will get an extra blank page at the end of your final generated document.

Put bookmarks around your document

First, check to see that bookmarks are visible in Word.

  1. From the to the Tools menu, choose Options.
  2. Choose the View tab.
  3. Make sure the Bookmarks box is checked.

Then, add put bookmarks around your document.

  1. Click and drag to select your entire document.
  2. From the Insert menu, choose Bookmark.
  3. Enter a name for your Bookmark and click Add.

Save your template and write the WordWriter code

You can now save your template and write your WordWriter code. Follow the usual procedure for populating repeat blocks with data from an array, database, or other data source.

Additional info in documentation:
Importing Multiple Rows in WordWriter Windows
Importing Multiple Rows in WordWriter Java

Limitation: At this time, WordWriter does not allow you to nest repeat blocks. Since each page is already part of a repeat block, if you wanted to insert multiple records on each page, you would not be able to do so.

Samples

Attached to this article is a sample that displays form letters, one per page. It has a page break before the first paragraph and bookmarks around the document. There is an ASP.NET C# sample as well as a Java Servlet sample.

ASP.NET

KB968_WordWriterMultiPage.zip contains the ASP.NET C# sample. To use this sample, you should:

  1. Unzip this file to a folder called WordWriterMultiPage.
  2. Right click the WordWriterMultiPage folder.
  3. On the Web Sharing tab, choose Share this Folder.
  4. Leave all the default values in the Edit Alias dialog that pops up and click OK.
  5. Run the sample by browsing to http://localhost/WordWriterMultiPage/index.aspx

NOTE: If you performed an automatic installation, then WordWriter will be in the Global Assembly Cache and this sample will run without any additional modifications. If you did a manual installation and did not install the WordWriter dll in the GAC, you will need to open this Project in Visual Studio 2003, Add a Reference to SAWW2NET.dll (usually found in C:\Program Files\SoftArtisans\OfficeWriter\WordWriter\), and recompile the Project.

Java

KB968_files2.zip contains the Java sample. This sample can be deployed in the same way you deploy the OfficeWriter Java samples that came with the product, with a few additional steps:

  1. Unzip the war file from the zip file
  2. Add your WordWriter-vX.X.X.jar and WordWriter-vX-License.jar files to the sample's war.
    1. Create a temporary directory anywhere on your hard drive.
    2. Copy the sample's war file to this directory.
    3. Inside this temporary directory, create a directory called "WEB-INF" and inside that create a directory called "lib".
    4. Copy the WordWriter jar files to the "lib" directory you just created. These files are usually located at C:\Program Files\SoftArtisans\OfficeWriter-vX.X-Java\WordWriter-vX.X
    5. Then, from a command prompt, use the jar command to add WordWriter jar files to the war file (it knows where to put them from the directory structure you just set up for them), like this:
      jar uvf wordWriterMultiPage.war WEB-INF
  3. Copy and deploy the war file to your Application server. For example, in Tomcat you would copy this file to the $TOMCAT_HOME/webapps directory. For other application servers, follow the steps outlined in our documentation regarding the OfficeWriter samples here. (You can now delete the temporary directory used in the previous step if desired.)
  4. Restart the Application Server if your server requires it. For example, Tomcat needs to be stopped and restarted using "shutdown.bat" and "startup.bat" unless you configured it to do this automatically.
  5. Run the sample by browsing to http://localhost:8080/wordWriterMultiPage/form.jsp
Related Links
OfficeWriter Home Page
Purchase OfficeWriter
OfficeWriter Enterprise Edition
Latest OfficeWriter News
OfficeWriter: Programmatic Runtime Control

Attachments
Attachments/KB986_WordWriterMultiPage.zip
Attachments/KB986_files2.zip
Created : 12/8/2004 6:02:49 PM (last modified : 1/3/2006 11:08:14 AM)
Rate this article!
Comments