Renders a page into a file.

 

   

Syntax
 

[C#]
void Save(string path)

[Visual Basic]
Sub Save(path As String)

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
path The destination file path.

 

   

Notes
 

Renders a page to a file. The current page at the time the operation has been created is rendered.

This method is similar in functionality to XRendering.Save(), but it can be safely called on different instances of RenderOperation from different threads even for the same page of the same document provided the page is not modified while being rendered because the document rendering options and the page ID are local to the operation. In the example below we show how to render document pages using parallel threads.

Furthermore, this method generates the following events, allowing fine tuning of the rendering operations:
  1. Before rendering begins, a ProcessingObject event of ProcessingSourceType.PageContent is generated. Set the event arguments' Cancel property to true to skip rendering altogether.
  2. When a PDF path stroking or filling operator is found in the page content, a ProcessingObject event of ProcessingSourceType.Path is generated. Set the event arguments' Cancel property to true to skip this object. The stream length and position can be retrieved via the StreamPosition and StreamLength properties. Set the stream position to null to skip the remaining of the stream.
  3. When a text PDF operator is found, a ProcessingObject event of ProcessingSourceType.Text is generated. The Unicode text can be retrieved in the Text property of the event Info property. the event cancel property to true to skip this object. The stream length and position can be retrieved via the StreamPosition and StreamLength properties. Set the stream position to null to skip the remaining of the stream.
  4. When a shading PDF operator is found, a ProcessingObject event of ProcessingSourceType.Shading is generated. The same comments of point 2 above apply, for skipping the object or retrieving/setting the stream position and length.
  5. When an image is found (inline or XObject), a ProcessingObject event of ProcessingSourceType.Image is generated. If the image is XObject, the indirect object can be retrieved via the event arguments' Object property. the event cancel property to true to skip this object. The stream length and position can be retrieved via the StreamPosition and StreamLength properties. Set the stream position to null to skip the remaining of the stream.
  6. When a Form XObject is found, a ProcessingObject event of ProcessingSourceType.FormXObject is generated. The indirect object can be retrieved via the event arguments' Object property. Set the event arguments' Cancel property to true to skip this object. The stream length and position can be retrieved via the StreamPosition and StreamLength properties. Set the stream position to null to skip the remaining of the stream. In addition, because Forms contain streams, a ProcessingObject event of ProcessingSourceType.Stream will follow. You can set the stream position to null to skip the stream at any time. That is events for the objects contained in the Form stream will be generated, as described in points 2 to 5. Setting the stream position to null for Form objects will skip the Form stream, not the entire page content.
Every ProcessingObject event is followed by a corresponding ProcessedObject, event with the same source type. The PageContent ProcessedObject event will be the last event received, in that all the page objects events are sandwiched between a PageContent processing and processed events. Similarly for form streams, all the form objects events are sandwiched between a Stream processing and processed events, which in turn are sandwiched between the FormXObject processing and processed events.
 
Any event property or event Info property not mentioned here are ignored.
 
   

Example
 

Here we render all the pages of the doc using 10 threads at a time. We alternate rendering format between jpg and tiff. We also alternate resolution between 150 and 300 dpi. Note how the RenderingOperation is created in the constructor of TheRenderingWorker. This is because at this point a copy of the rendering options is made. Had we created the RenderingOperation in DoWork, we would have picked up only the last doc.Rendering.DotsPerInch, because the threads are started in the following loop. Also note how we dispose the operation in DoWork, to release resources stored on the native side (the copy of the rendering options basically).

[C#]class RenderingWorker {
    private string mPath;
    private RenderOperation mOp;

    public RenderingWorker(Doc inDoc, string inPath) {
        mPath = inPath;
        mOp = new RenderOperation(inDoc);
    }

    public void DoWork() {
        mOp.Save(mPath);
        mOp.Dispose();
    }
}

Doc doc = new Doc();
doc.Read(Server.MapPath("ABCpdf.pdf"));
string[] theExts = { ".jpg", ".tif" };
int[] theDpis = { 150, 300 };
Thread[] threadList = new Thread[10];
int pageNum = 1, pageCount = doc.PageCount;
while (pageNum <= pageCount) {
    int count = 0;
    while (count < threadList.Length && pageNum <= pageCount) {
        doc.Rendering.DotsPerInch = theDpis[(pageNum - 1) % 2];
        doc.PageNumber = pageNum;
        string path = Server.MapPath("ABCpdf" + pageNum.ToString() + theExts[(pageNum - 1) % 2]);

        threadList[count] = new Thread(new RenderingWorker(doc, path).DoWork);
        ++count;
        ++pageNum;
    }
    for (int i = 0; i < count; ++i)
        threadList[i].Start();
    for (int i = 0; i < count; ++i)
        threadList[i].Join();
}
doc.Clear();

[Visual Basic]Class RenderingWorker
    Private mPath As String
    Private mOp As RenderOperation

    Public Sub New(ByVal inDoc As Doc, ByVal inPath As String)
        mPath = inPath
        mOp = New RenderOperation(inDoc)
    End Sub

    Public Sub DoWork()
        mOp.Save(mPath)
        mOp.Dispose()
    End Sub
End Class

Dim doc As Doc = new Doc()
doc.Read(Server.MapPath("ABCpdf.pdf"))
Dim theExts As String() = {".jpg", ".tif"}
Dim theDpis As Integer() = {150, 300}
Dim threadList(10 - 1) As Thread
Dim pageNum As Integer = 1, pageCount As Integer = doc.PageCount
While pageNum <= pageCount
    Dim count As Integer = 0
    While count < threadList.Length AndAlso pageNum <= pageCount
        doc.Rendering.DotsPerInch = theDpis((pageNum - 1) Mod 2)
        doc.PageNumber = pageNum
        Dim path As String = Server.MapPath(("ABCpdf" & pageNum.ToString()) + theExts((pageNum - 1) Mod 2))

        threadList(count) = New Thread(AddressOf New RenderingWorker(doc, path).DoWork)
        count += 1
        pageNum += 1
    End While

    For i As Integer = 0 To count - 1
        threadList(i).Start()
    Next
    For i As Integer = 0 To count - 1
        threadList(i).Join()
    Next
End While
doc.Clear()