Back to Devexpress

PdfDocumentProcessor.LoadDocument(Stream, Boolean) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-dot-loaddocument-x28-system-dot-io-dot-stream-system-dot-boolean-x29.md

latest7.1 KB
Original Source

PdfDocumentProcessor.LoadDocument(Stream, Boolean) Method

Opens a PDF document from the specified stream using detach stream mode.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public void LoadDocument(
    Stream stream,
    bool detachStreamAfterLoadComplete
)
vb
Public Sub LoadDocument(
    stream As Stream,
    detachStreamAfterLoadComplete As Boolean
)

Parameters

NameTypeDescription
streamStream

A Stream object.

| | detachStreamAfterLoadComplete | Boolean |

true the PDF Document API component completes all input operations after loading a document; false the stream should not be closed or modified until the PDF Document API component finishes using a document.

|

Remarks

The PDF Document API component expects that the input stream will not be modified or closed before the component finishes using a document. Pass true as the detachStreamAfterLoadComplete method parameter to force the PDF Document API component to complete all input operations after loading a document.

If the PdfProcessor fails to load the document, an ArgumentException is thrown.

Example

View Example

The code sample below uses PdfFormData to set form field values:

csharp
// Load a document with an interactive form.
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {
    documentProcessor.LoadDocument(filePath + fileName + ".pdf");

    // Obtain interactive form data from a document.
    PdfFormData formData = documentProcessor.GetFormData();

    // Specify the value for FirstName and LastName text boxes.
    formData["FirstName"].Value = "Janet";
    formData["LastName"].Value = "Leverling";

    // Specify the value for the Gender radio group.
    formData["Gender"].Value = "Female";

    // Specify the check box checked appearance name.
    formData["Check"].Value = "Yes";

    // Specify values for the Category list box.
    formData["Category"].Value = new string[] { "Entertainment", "Meals", "Morale" };

    // Obtain data from the Address form field and specify values for Address child form fields.
    PdfFormData address = formData["Address"];

    // Specify the value for the Country combo box. 
    address["Country"].Value = "United States";

    // Specify the value for City and Address text boxes. 
    address["City"].Value = "California";
    address["Address"].Value = "20 Maple Avenue";

    // Apply data to the interactive form. 
    documentProcessor.ApplyFormData(formData);

    // Save the modified document.
    documentProcessor.SaveDocument(filePath + fileName + "_new.pdf");
}
vb
' Load a document with an interactive form.
Using documentProcessor As New PdfDocumentProcessor()
    documentProcessor.LoadDocument(filePath & fileName & ".pdf")

    ' Obtain interactive form data from a document.
    Dim formData As PdfFormData = documentProcessor.GetFormData()

    ' Specify the value for FirstName and LastName text boxes.
    formData("FirstName").Value = "Janet"
    formData("LastName").Value = "Leverling"

    ' Specify the value for the Gender radio group.
    formData("Gender").Value = "Female"

    ' Specify the check box checked appearance name.
    formData("Check").Value = "Yes"

    ' Specify values for the Category list box.
    formData("Category").Value = New String() { "Entertainment", "Meals", "Morale" }

    ' Obtain data from the Address form field and specify values for Address child form fields.
    Dim address As PdfFormData = formData("Address")

    ' Specify the value for the Country combo box. 
    address("Country").Value = "United States"

    ' Specify the value for City and Address text boxes. 
    address("City").Value = "California"
    address("Address").Value = "20 Maple Avenue"

    ' Apply data to the interactive form. 
    documentProcessor.ApplyFormData(formData)

    ' Save the modified document.
    documentProcessor.SaveDocument(filePath & fileName & "_new.pdf")

End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the LoadDocument(Stream, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

office-file-api-in-web-api-app/CS/Controllers/PdfController.cs#L41

csharp
stream.Seek(0, SeekOrigin.Begin);
    processor.LoadDocument(stream, true);
}

asp-net-web-forms-implement-pdf-viewer/CS/PdfViewer.ascx.cs#L76

csharp
using (MemoryStream stream = new MemoryStream(value)) {
    DocumentProcessor.LoadDocument(stream, true);
    BindDataView();

office-file-api-ai-implementation/CS/BusinessObjects/Helpers.cs#L206

csharp
stream.Seek(0, SeekOrigin.Begin);
    processor.LoadDocument(stream, true);
}

asp-net-web-forms-implement-pdf-viewer/VB/PdfViewer.ascx.vb#L84

vb
Using stream As System.IO.MemoryStream = New System.IO.MemoryStream(value)
    Me.DocumentProcessor.LoadDocument(stream, True)
    Me.BindDataView()

See Also

DetachStreamAfterLoadComplete

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace