C1PrintDocument : StartDoc-EndDoc Vs Generate

Many times, when the users want to insert a new page in C1PrintDocument, they get confused whether to use StartDoc-EndDoc methods or use Generate method or use both. C1PrintDocument can be created by either using StartDoc-EndDoc methods or by using Generate method. Both these methods appear similar but are different in terms of their implementation. In this blog, lets discuss on these two ways of creating documents and inserting new page in each scenario.

StartDoc()-EndDoc() Methods

The StartDoc method marks the start of generation of the document and the EndDoc finishes the generation of the document. The StartDoc-EndDoc is used when the render objects are to be added into the block flow of the document i.e. using the RenderBlock(), RenderDirect() and RenderInline() methods as follows:


Generate() Method

The Generate method generates the document using the RefreshCalculatedValues refresh mode. You may refer to this link to gather more info about the RefreshModes. The Generate method is used when the render objects are added directly into the body of the document using the code as following:

this.c1PrintDocument1.Body.Children.Add(new C1.C1Preview.RenderText("Hello, World!"));

Since both methods are called to generate the document, they can’t be used together. If using the StartDoc, the document generation has already been started, hence one cannot make a call to refresh/regenerate the document in between by using the Generate method.

How to insert new Page using these methods?

  1. In case you are using Generate() method to generate the document, you would need to insert the page break before or after a Render object added to this document. For example, the following code snippet can be used to insert a new page between the two Render Tables:

    rt1.BreakAfter = BreakEnum.Page;  
  2. When using StartDoc-EndDoc methods, a new page can easily be inserted using the NewPage method of the C1PrintDocument:


Please refer to the sample applications for complete implementation. Download C# Sample Download VB Sample


GrapeCity Developer Tools
comments powered by Disqus