Skip to main content
A newer version of this page is available. .

PdfDocumentProcessor.SaveDocument(Stream, PdfSaveOptions) Method

Saves the current PDF document to the specified stream with encryption settings and document signature.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Docs.v18.2.dll

Declaration

public void SaveDocument(
    Stream stream,
    PdfSaveOptions options
)

Parameters

Name Type Description
stream Stream

A Stream value, specifying the location of the saved document.

options PdfSaveOptions

A PdfSaveOptions that contains the encryption settings and document signature that should be saved.

Remarks

The SaveDocument method expects the input stream will not be closed or modified while a PDF document is saved (the detachStream parameter is set to false in this method). Be aware that disposing of an output stream that has not been detached may cause errors on an attempt to apply further changes to a document. If you want to close the stream when a document is saved, call another overloaded SaveDocument method with the detachStream parameter enabled.

Important

Using the same stream for loading and saving a document may cause unpredictable results, since the detachStream parameter is set to false in this method.

Example

This example illustrates how to add a visual signature to a PDF document.

To accomplish this task, do the following:

using DevExpress.Pdf;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace PDFSignature {
    class Program {
        static void Main(string[] args) {

            // Create a PDF document processor.
            using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {

                // Load a PDF document. 
                documentProcessor.LoadDocument(@"..\..\Demo.pdf");

                // Create a visual signature using certificate, image data, and specifying  page number, signature bounds and rotation angle. 
                X509Certificate2 certificate = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo");
                byte[] imageData = File.ReadAllBytes("..\\..\\Signature.png");
                int pageNumber = 1;
                int angleInDegrees = 45; 
                double angleInRadians = angleInDegrees * (Math.PI / 180);
                PdfOrientedRectangle signatureBounds = new PdfOrientedRectangle(new PdfPoint(620, 210), 250, 90, angleInRadians);
                PdfSignature signature = new PdfSignature(certificate, imageData, pageNumber, signatureBounds);

                // Specify signing location, contact info and reason.
                signature.Location = "USA";
                signature.ContactInfo = "john.smith@example.com";
                signature.Reason = "Approved";

                // Save the signed document.
                documentProcessor.SaveDocument(@"..\..\SignedDocument.pdf", new PdfSaveOptions() { Signature = signature });
            }
        }
    }
}
See Also