Inserting Documents Dynamically

You can insert contents of outer documents to your reports dynamically using doc tags. A doc tag denotes a placeholder within a template for a document to be inserted during run time.

Syntax of a doc tag is defined as follows:

<<doc [document_expression]>>

And simply call the assembler method to generate report like following code snippets:

An expression declared within a doc tag is used by the assembler to load a document to be inserted during runtime. The expression must return a value of one of the following types:

  • A byte array containing document data
  • An InputStream instance able to read document data
  • An instance of the Document class
  • A string containing a document URI, path, or Base64-encoded document data

While building a report, an expression declared within a doc tag is evaluated and its result is used to load a document which content replaces the doc tag then.

By default, while inserting content of an outer document, the engine applies corresponding styles of a template document. This makes content of a result document look more consistent. However, you can keep source formatting for content being inserted by using a sourceStyles switch as shown in the following snippet:

<<doc [document_expression] -sourceStyles>>

By default, a document being inserted is not checked against template syntax and is not populated with data. However, you can enable this by using a build switch as follows.

<<doc [document_expression] -build>>

When a build switch is used, the assembler treats a document being inserted as a template that can access the following data available at the scope of a corresponding doc tag:

© Aspose Pty Ltd 2001-2022. All Rights Reserved.