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:
- Right click anywhere within the first paragraph of your template and choose Paragraph from the context menu.
Left click anywhere within the first paragraph and choose Paragraph from the Format menu.
- Choose the Line and Page Breaks tab.
- 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.
- From the to the Tools menu, choose Options.
- Choose the View tab.
- Make sure the Bookmarks box is checked.
Then, add put bookmarks around your document.
- Click and drag to select your entire document.
- From the Insert menu, choose Bookmark.
- 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.
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.
KB968_WordWriterMultiPage.zip contains the ASP.NET C# sample. To use this sample, you should:
- Unzip this file to a folder called WordWriterMultiPage.
- Right click the WordWriterMultiPage folder.
- On the Web Sharing tab, choose Share this Folder.
- Leave all the default values in the Edit Alias dialog that pops up and click OK.
- 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.
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:
- Unzip the war file from the zip file
- Add your WordWriter-vX.X.X.jar and WordWriter-vX-License.jar files to the sample's war.
- Create a temporary directory anywhere on your hard drive.
- Copy the sample's war file to this directory.
- Inside this temporary directory, create a directory called "WEB-INF" and inside that create a directory called "lib".
- 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
- 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
- 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.)
- 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.
- Run the sample by browsing to http://localhost:8080/wordWriterMultiPage/form.jsp