Document .Net

allows your App to do all with documents.

Read More

Simple API


Single Logical Tree to work with five formats: PDF, DOCX, RTF, HTML and Text.

Implementation of any software features of a component will require minimal programming knowledge and a level of developer.

Many examples of code implementation make it easy to implement any task.

Simple API Documetn .Net

Why choose Document .NET?

Save Time

The writing of own classes to support PDF, RTF and DOCX formats in C# requires a lot of days of hard work and takes thousands C# code lines. Libraries will save a lot time and need only to add the reference to "SautinSoft.Document.dll" and write 5-7 C# code lines.

Simple pricing.

Flexible licensing and partnership opportunities

The one time price.

Pay a one time and can use Libraries for a whole life without any additional fees. License will never expires.

Thoroughly documented

We provide sample projects, demos, API docs and more for every single feature to get you up to speed quickly.

Introducing

We’ve thoroughly revamped our documentation, giving you new code examples and updates to developer guides.

-----

Our products are developer-friendly: we put a lot of source code examples and cases so you can start using the new technology in minutes without reading the documentation.

Reqular Updates

Product updates are performed every two months.

Experience

SautinSoft team have over 17 years experience in the .Net software component market.

Human Support

Talk directly with our development team

Popular code examples:


We sing the best code examples

Convert a document to another format

using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ConvertFromFile();
            ConvertFromStream();
        }

        /// <summary>
        /// Convert PDF to DOCX (file to file).
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/convert-document.php
        /// </remarks>
        static void ConvertFromFile()
        {
            string inpFile = @"..\..\example.pdf";
            string outFile = @"Result.docx";

            DocumentCore dc = DocumentCore.Load(inpFile);
            dc.Save(outFile);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }

        /// <summary>
        /// Convert PDF to HTML (using Stream).
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/convert-document.php
        /// </remarks>
        static void ConvertFromStream()
        {

            // We need files only for demonstration purposes.
            // The conversion process will be done completely in memory.
            string inpFile = @"..\..\example.pdf";
            string outFile = @"Result.html";
            byte[] inpData = File.ReadAllBytes(inpFile);
            byte[] outData = null;

            using (MemoryStream msInp = new MemoryStream(inpData))
            {

                // Load a document.
                DocumentCore dc = DocumentCore.Load(msInp, new PdfLoadOptions()
                {
                    PreserveGraphics = true,
                    DetectTables = true
                });

                // Save the document to HTML-fixed format.
                using (MemoryStream outMs = new MemoryStream())
                {
                    dc.Save(outMs, new HtmlFixedSaveOptions()
                    {
                        CssExportMode = CssExportMode.Inline,
                        EmbedImages = true
                    });
                    outData = outMs.ToArray();                    
                }
                // Show the result for demonstration purposes.
                if (outData != null)
                {
                    File.WriteAllBytes(outFile, outData);
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                }
            }
        }
    }
}
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        ConvertFromFile()
        ConvertFromStream()
    End Sub

    ''' <summary>
    ''' Convert PDF to DOCX (file to file).
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/convert-document.php
    ''' </remarks>
    Sub ConvertFromFile()
        Dim inpFile As String = "..\example.pdf"
        Dim outFile As String = "Result.docx"

        Dim dc As DocumentCore = DocumentCore.Load(inpFile)
        dc.Save(outFile)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
    End Sub

    ''' <summary>
    ''' Convert PDF to HTML (using Stream).
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/convert-document.php
    ''' </remarks>
    Sub ConvertFromStream()

        ' We need files only for demonstration purposes.
        ' The conversion process will be done completely in memory.
        Dim inpFile As String = "..\example.pdf"
        Dim outFile As String = "Result.html"
        Dim inpData() As Byte = File.ReadAllBytes(inpFile)
        Dim outData() As Byte = Nothing

        Using msInp As New MemoryStream(inpData)

            ' Load a document.
            Dim dc As DocumentCore = DocumentCore.Load(msInp, New PdfLoadOptions() With {
                .PreserveGraphics = True,
                .DetectTables = True
            })

            ' Save the document to HTML-fixed format.
            Using outMs As New MemoryStream()
                dc.Save(outMs, New HtmlFixedSaveOptions() With {
                    .CssExportMode = CssExportMode.Inline,
                    .EmbedImages = True
                })
                outData = outMs.ToArray()
            End Using
            ' Show the result for demonstration purposes.
            If outData IsNot Nothing Then
                File.WriteAllBytes(outFile, outData)
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If
        End Using
    End Sub
End Module

How to create a PDF document

using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            CreatePdf();
        }

        /// 
        /// Creates a new document and saves it into PDF format.
        /// 
        /// 
        /// Details: https://www.sautinsoft.com/products/document/examples/create-pdf-document-net-csharp-vb.php
        /// 
        public static void CreatePdf()
        {
            // Set a path to our pdf file.
            string pdfPath = @"Result.pdf";

            // Let's create a simple PDF document.
            DocumentCore dc = new DocumentCore();

            // Add new section.
            Section section = new Section(dc);
            dc.Sections.Add(section);

            // Let's set page size A4.
            section.PageSetup.PaperType = PaperType.A4;

            // Add two paragraphs using different ways:

            // Way 1: Add 1st paragraph.
            Paragraph par1 = new Paragraph(dc);
            par1.ParagraphFormat.Alignment = HorizontalAlignment.Center;
            section.Blocks.Add(par1);

            // Let's create a characterformat for text in the 1st paragraph.
            CharacterFormat cf = new CharacterFormat() { FontName = "Verdana", Size = 16, FontColor = Color.Orange };

            Run text1 = new Run(dc, "This is a first line in 1st paragraph!");
            text1.CharacterFormat = cf;
            par1.Inlines.Add(text1);

            // Let's add a line break into our paragraph.
            par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak));

            Run text2 = text1.Clone();
            text2.Text = "Let's type a second line.";
            par1.Inlines.Add(text2);

            // Way 2 (easy): Add 2nd paragraph using ContentRange.
            dc.Content.End.Insert("\nThis is a first line in 2nd paragraph.", new CharacterFormat() { Size = 25, FontColor = Color.Blue, Bold = true });
            SpecialCharacter lBr = new SpecialCharacter(dc, SpecialCharacterType.LineBreak);
            dc.Content.End.Insert(lBr.Content);
            dc.Content.End.Insert("This is a second line.", new CharacterFormat() { Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single });

            // Save PDF to a file
            dc.Save(pdfPath, new PdfSaveOptions());

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true });
        }
    }
}
Imports SautinSoft.Document

Module Sample
    Sub Main()
        CreatePdf()
    End Sub

    ''' 
    ''' Creates a new document and saves it into PDF format.
    ''' 
    ''' 
    ''' Details: https://www.sautinsoft.com/products/document/examples/create-pdf-document-net-csharp-vb.php
    ''' 
    Sub CreatePdf()
        ' Set a path to our pdf file.
        Dim pdfPath As String = "Result.pdf"

        ' Let's create a simple PDF document.
        Dim dc As New DocumentCore()

        ' Add new section.
        Dim section As New Section(dc)
        dc.Sections.Add(section)

        ' Let's set page size A4.
        section.PageSetup.PaperType = PaperType.A4

        ' Add two paragraphs using different ways:

        ' Way 1: Add 1st paragraph.
        Dim par1 As New Paragraph(dc)
        par1.ParagraphFormat.Alignment = HorizontalAlignment.Center
        section.Blocks.Add(par1)

        ' Let's create a characterformat for text in the 1st paragraph.
        Dim cf As New CharacterFormat() With {
            .FontName = "Verdana",
            .Size = 16,
            .FontColor = Color.Orange
        }

        Dim text1 As New Run(dc, "This is a first line in 1st paragraph!")
        text1.CharacterFormat = cf
        par1.Inlines.Add(text1)

        ' Let's add a line break into our paragraph.
        par1.Inlines.Add(New SpecialCharacter(dc, SpecialCharacterType.LineBreak))

        Dim text2 As Run = text1.Clone()
        text2.Text = "Let's type a second line."
        par1.Inlines.Add(text2)

        ' Way 2 (easy): Add 2nd paragraph using ContentRange.
        dc.Content.End.Insert(vbLf & "This is a first line in 2nd paragraph.", New CharacterFormat() With {
            .Size = 25,
            .FontColor = Color.Blue,
            .Bold = True
        })
        Dim lBr As New SpecialCharacter(dc, SpecialCharacterType.LineBreak)
        dc.Content.End.Insert(lBr.Content)
        dc.Content.End.Insert("This is a second line.", New CharacterFormat() With {
            .Size = 20,
            .FontColor = Color.DarkGreen,
            .UnderlineStyle = UnderlineType.Single
        })

        ' Save PDF to a file
        dc.Save(pdfPath, New PdfSaveOptions())

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfPath) With {.UseShellExecute = True})
    End Sub
End Module

How to combine multiple files into single document using

using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft.Document;
namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            MergeMultipleDocuments();
        }
        /// <summary>
        /// This sample shows how to merge multiple DOCX, RTF, PDF and Text files.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/merge-multiple-files-net-csharp-vb.php
        /// </remarks>
        public static void MergeMultipleDocuments()
        {
            // Path to our combined document.
            string singlePDFPath = "Single.pdf";
            string workingDir = @"..\..\";
            List<string> supportedFiles = new List<string>();
            // Fill the collection 'supportedFiles' by *.docx, *.pdf and *.txt.
            foreach (string file in Directory.GetFiles(workingDir, "*.*"))
            {
                string ext = Path.GetExtension(file).ToLower();

                if (ext == ".docx" || ext == ".pdf" || ext == ".txt")
                    supportedFiles.Add(file);
            }
            // Create single pdf.
            DocumentCore singlePDF = new DocumentCore();
            foreach (string file in supportedFiles)
            {
                DocumentCore dc = DocumentCore.Load(file);
                Console.WriteLine("Adding: {0}...", Path.GetFileName(file));
                // Create import session.
                ImportSession session = new ImportSession(dc, singlePDF, StyleImportingMode.KeepSourceFormatting);
                // Loop through all sections in the source document.
                foreach (Section sourceSection in dc.Sections)
                {
                    // Because we are copying a section from one document to another,
                    // it is required to import the Section into the destination document.
                    // This adjusts any document-specific references to styles, bookmarks, etc.
                    //
                    // Importing a element creates a copy of the original element, but the copy
                    // is ready to be inserted into the destination document.
                    Section importedSection = singlePDF.Import<Section>(sourceSection, true, session);
                    // First section start from new page.
                    if (dc.Sections.IndexOf(sourceSection) == 0)
                        importedSection.PageSetup.SectionStart = SectionStart.NewPage;
                    // Now the new section can be appended to the destination document.
                    singlePDF.Sections.Add(importedSection);
                }
            }
            // Save single PDF to a file.
            singlePDF.Save(singlePDFPath);
            // Open the result for demonstration purposes.
           System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(singlePDFPath) { UseShellExecute = true });
        }
    }
}
                                
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports SautinSoft.Document
Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
            MergeMultipleDocuments()
        End Sub
        ''' <summary>
        ''' This sample shows how to merge multiple DOCX, RTF, PDF and Text files.
        ''' </summary>
        ''' <remarks>
        ''' Details: https://sautinsoft.com/products/document/examples/merge-multiple-files-net-csharp-vb.php
        ''' </remarks>
        Public Shared Sub MergeMultipleDocuments()
            ' Path to our combined document.
            Dim singlePDFPath As String = "Single.pdf"
            Dim workingDir As String = "..\"
            Dim supportedFiles As New List(Of String)()
            ' Fill the collection 'supportedFiles' by *.docx, *.pdf and *.txt.
            For Each file As String In Directory.GetFiles(workingDir, "*.*")
                Dim ext As String = Path.GetExtension(file).ToLower()
                If ext = ".docx" OrElse ext = ".pdf" OrElse ext = ".txt" Then
                    supportedFiles.Add(file)
                End If
            Next file
            ' Create single pdf.
            Dim singlePDF As New DocumentCore()
            For Each file As String In supportedFiles
                Dim dc As DocumentCore = DocumentCore.Load(file)
                Console.WriteLine("Adding: {0}...", Path.GetFileName(file))
                ' Create import session.
                Dim session As New ImportSession(dc, singlePDF, StyleImportingMode.KeepSourceFormatting)
                ' Loop through all sections in the source document.
                For Each sourceSection As Section In dc.Sections
                    ' Because we are copying a section from one document to another,
                    ' it is required to import the Section into the destination document.
                    ' This adjusts any document-specific references to styles, bookmarks, etc.
                    '
                    ' Importing a element creates a copy of the original element, but the copy
                    ' is ready to be inserted into the destination document.
                    Dim importedSection As Section = singlePDF.Import(Of Section)(sourceSection, True, session)
                    ' First section start from new page.
                    If dc.Sections.IndexOf(sourceSection) = 0 Then
                        importedSection.PageSetup.SectionStart = SectionStart.NewPage
                    End If
                    ' Now the new section can be appended to the destination document.
                    singlePDF.Sections.Add(importedSection)
                Next sourceSection
            Next file
            ' Save single PDF to a file.
            singlePDF.Save(singlePDFPath)
            ' Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(singlePDFPath) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
                            

How to save a document in PDF

using System.IO;
using SautinSoft.Document;
namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            SaveToPdfFile();
            SaveToPdfStream();
        }
        /// <summary>
        /// Creates a new document and saves it as PDF file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/save-document-as-pdf-net-csharp-vb.php
        /// </remarks>
        static void SaveToPdfFile()
        {
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!\nFrom file.", new CharacterFormat() { FontColor = Color.Green, Size = 20});
            string filePath = @"Result-file.pdf";
            dc.Save(filePath, new PdfSaveOptions()
            {
                Compliance = PdfCompliance.PDF_A,
                PreserveFormFields = true
            });
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
        /// <summary>
        /// Creates a new document and saves it as PDF/A using MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/save-document-as-pdf-net-csharp-vb.php
        /// </remarks>
        static void SaveToPdfStream()
        {
            // There variables are necessary only for demonstration purposes.
            byte[] fileData = null;
            string filePath = @"Result-stream.pdf";
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!\nFrom MemoryStream.", new CharacterFormat() { FontColor = Color.Orange, Size = 20 });
            // Let's save our document to a MemoryStream.
            using (MemoryStream ms = new MemoryStream())
            {
                dc.Save(ms, new PdfSaveOptions()
                {
                    PageIndex = 0,
                    PageCount = 1,
                    Compliance = PdfCompliance.PDF_A
                });
                fileData = ms.ToArray();
            }
            File.WriteAllBytes(filePath, fileData);
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
    Sub Main()
        SaveToPdfFile()
        SaveToPdfStream()
    End Sub
    ''' <summary>
    ''' Creates a new document and saves it as PDF file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/save-document-as-pdf-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToPdfFile()
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!" & vbLf & "From file.", New CharacterFormat() With {
            .FontColor = Color.Green,
            .Size = 20
        })
        Dim filePath As String = "Result-file.pdf"
        dc.Save(filePath, New PdfSaveOptions() With {
            .Compliance = PdfCompliance.PDF_A,
            .PreserveFormFields = True
        })
        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
    ''' <summary>
    ''' Creates a new document and saves it as PDF/A using MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/save-document-as-pdf-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToPdfStream()
        ' There variables are necessary only for demonstration purposes.
        Dim fileData() As Byte = Nothing
        Dim filePath As String = "Result-stream.pdf"
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!" & vbLf & "From MemoryStream.", New CharacterFormat() With {
            .FontColor = Color.Orange,
            .Size = 20
        })
        ' Let's save our document to a MemoryStream.
        Using ms As New MemoryStream()
            dc.Save(ms, New PdfSaveOptions() With {
                .PageIndex = 0,
                .PageCount = 1,
                .Compliance = PdfCompliance.PDF_A
            })
            fileData = ms.ToArray()
        End Using
        File.WriteAllBytes(filePath, fileData)
        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})

    End Sub
End Module

How to load a HTML document

using System;
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {

        static void Main(string[] args)
        {
            LoadHtmlFromFile();
            //LoadHtmlFromStream();
        }

        /// 
        /// Loads an HTML document into DocumentCore (dc) from a file.
        /// 
        /// 
        /// Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
        /// 
        static void LoadHtmlFromFile()
        {
            string filePath = @"..\..\example.html";
            // The file format is detected automatically from the file extension: ".html".
            // But as shown in the example below, we can specify HtmlLoadOptions as 2nd parameter
            // to explicitly set that a loadable document has HTML format.
            DocumentCore dc = DocumentCore.Load(filePath);
            if (dc != null)
                Console.WriteLine("Loaded successfully!");
            Console.ReadKey();
        }

        /// 
        /// Loads an HTML document into DocumentCore (dc) from a MemoryStream.
        /// 
        /// 
        /// Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
        /// 
        static void LoadHtmlFromStream()
        {
            // Get document bytes.
            byte[] fileBytes = File.ReadAllBytes(@"..\..\example.html");

            DocumentCore dc = null;

            // Create a MemoryStream
            using (MemoryStream ms = new MemoryStream(fileBytes))
            {
                // Load a document from the MemoryStream.
                // Specifying HtmlLoadOptions we explicitly set that a loadable document is HTML.
                dc = DocumentCore.Load(ms, new HtmlLoadOptions());
            }
            if (dc != null)
                Console.WriteLine("Loaded successfully!");
            Console.ReadKey();
        }
    }
}
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        LoadHtmlFromFile()
        'LoadHtmlFromStream();
    End Sub

    ''' 
    ''' Loads an HTML document into DocumentCore (dc) from a file.
    ''' 
    ''' 
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
    ''' 
    Sub LoadHtmlFromFile()
        Dim filePath As String = "..\example.html"
        ' The file format is detected automatically from the file extension: ".html".
        ' But as shown in the example below, we can specify HtmlLoadOptions as 2nd parameter
        ' to explicitly set that a loadable document has HTML format.
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
            Console.ReadKey()
        End If
    End Sub

    ''' 
    ''' Loads an HTML document into DocumentCore (dc) from a MemoryStream.
    ''' 
    ''' 
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
    ''' 
    Sub LoadHtmlFromStream()
        ' Get document bytes.
        Dim fileBytes() As Byte = File.ReadAllBytes("..\example.html")

        Dim dc As DocumentCore = Nothing

        ' Create a MemoryStream
        Using ms As New MemoryStream(fileBytes)
            ' Load a document from the MemoryStream.
            ' Specifying HtmlLoadOptions we explicitly set that a loadable document is HTML.
            dc = DocumentCore.Load(ms, New HtmlLoadOptions())
        End Using
        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
            Console.ReadKey()
        End If
    End Sub
End Module

Create digitally signed PDF

using System.IO;
using System.Linq;
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            DigitalSignature();
        }
        /// 
        /// Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it in a PDF document with the digital signature.
        /// 
        /// 
        /// Details: https://sautinsoft.com/products/document/examples/digital-signature-net-csharp-vb.php
        /// 
        public static void DigitalSignature()
        {
            // Path to a loadable document.
            string loadPath = @"..\..\digitalsignature.docx";
            string savePath = "Result.pdf";
            DocumentCore dc = DocumentCore.Load(loadPath);
            // Create a new invisible Shape for the digital signature.
            // Place the Shape into top-left corner (0 mm, 0 mm) of page.
            Shape signatureShape = new Shape(dc, Layout.Floating(new HorizontalPosition(0f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                    new VerticalPosition(0f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), new Size(1, 1)));
            ((FloatingLayout)signatureShape.Layout).WrappingStyle = WrappingStyle.InFrontOfText;
            signatureShape.Outline.Fill.SetEmpty();
            // Find a first paragraph and insert our Shape inside it.
            Paragraph firstPar = dc.GetChildElements(true).OfType().FirstOrDefault();
            firstPar.Inlines.Add(signatureShape);
            // Picture which symbolizes a handwritten signature.
            Picture signaturePict = new Picture(dc, @"..\..\signature.png");
            // Signature picture will be positioned:
            // 14.5 cm from Top of the Shape.
            // 4.5 cm from Left of the Shape.
            signaturePict.Layout = Layout.Floating(
               new HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page),
               new VerticalPosition(14.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page),
               new Size(20, 10, LengthUnit.Millimeter));
            PdfSaveOptions options = new PdfSaveOptions();
            // Path to the certificate (*.pfx).
            options.DigitalSignature.CertificatePath = @"..\..\sautinsoft.pfx";
            // The password for the certificate.
            // Each certificate is protected by a password.
            // The reason is to prevent unauthorized the using of the certificate.
            options.DigitalSignature.CertificatePassword = "123456789";
            // Additional information about the certificate.
            options.DigitalSignature.Location = "World Wide Web";
            options.DigitalSignature.Reason = "Document.Net by SautinSoft";
            options.DigitalSignature.ContactInfo = "info@sautinsoft.com";
            // Placeholder where signature should be visualized.
            options.DigitalSignature.SignatureLine = signatureShape;
            // Visual representation of digital signature.
            options.DigitalSignature.Signature = signaturePict;
            dc.Save(savePath, options);
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true });
        }
    }
}
                                
Imports System
Imports System.Linq
Imports System.IO
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Module Sample
    Sub Main()
        DigitalSignature()
    End Sub
    ''' <summary>
    ''' Load an existing document (*.docx, *.rtf, *.pdf, *.html, *.txt, *.pdf) and save it in a PDF document with the digital signature.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/digital-signature-net-csharp-vb.php
    ''' </remarks>
    Sub DigitalSignature()
        ' Path to a loadable document.
        Dim loadPath As String = "..\digitalsignature.docx"
        Dim savePath As String = "Result.pdf"
        Dim dc As DocumentCore = DocumentCore.Load(loadPath)
        ' Create a new invisible Shape for the digital signature.       
        ' Place the Shape into top-left corner (0 mm, 0 mm) of page.
        Dim signatureShape As New Shape(dc, Layout.Floating(New HorizontalPosition(0F, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin), New VerticalPosition(0F, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin), New Size(1, 1)))
        CType(signatureShape.Layout, FloatingLayout).WrappingStyle = WrappingStyle.InFrontOfText
        signatureShape.Outline.Fill.SetEmpty()
        ' Find a first paragraph and insert our Shape inside it.
        Dim firstPar As Paragraph = dc.GetChildElements(True).OfType(Of Paragraph)().FirstOrDefault()
        firstPar.Inlines.Add(signatureShape)
        ' Picture which symbolizes a handwritten signature.
        Dim signaturePict As New Picture(dc, "..\signature.png")
        ' Signature picture will be positioned:
        ' 14.5 cm from Top of the Shape.
        ' 4.5 cm from Left of the Shape.
        signaturePict.Layout = Layout.Floating(New HorizontalPosition(4.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), New VerticalPosition(14.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), New Size(20, 10, LengthUnit.Millimeter))
        Dim options As New PdfSaveOptions()
        ' Path to the certificate (*.pfx).
        options.DigitalSignature.CertificatePath = "..\sautinsoft.pfx"
        ' The password for the certificate.
        ' Each certificate is protected by a password.
        ' The reason is to prevent unauthorized the using of the certificate.
        options.DigitalSignature.CertificatePassword = "123456789"
        ' Additional information about the certificate.
        options.DigitalSignature.Location = "World Wide Web"
        options.DigitalSignature.Reason = "Document.Net by SautinSoft"
        options.DigitalSignature.ContactInfo = "info@sautinsoft.com"
        ' Placeholder where signature should be visualized.
        options.DigitalSignature.SignatureLine = signatureShape
        ' Visual representation of digital signature.
        options.DigitalSignature.Signature = signaturePict
        dc.Save(savePath, options)
        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(savePath) With {.UseShellExecute = True})
    End Sub
End Module
                            

How to add & read built-in and custom document properties

using System;
using SautinSoft.Document;
using SautinSoft.Document.Drawing;
using System.IO;
using System.Linq;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            CreateDocumentProperties();
            ReadDocumentProperties();
        }

        /// 
        /// Create a new document (DOCX) with some built-in properties.
        /// 
		/// 
        /// Details: https://sautinsoft.com/products/document/examples/document-properties.php
        /// 
        public static void CreateDocumentProperties()
        {
            string filePath = @"..\..\DocumentProperties.docx";

            DocumentCore dc = new DocumentCore();

            // Let's create a simple inscription.
            dc.Content.End.Insert("Hello World!!!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });

            // Let's add some documents properties: Author, Subject, Company.
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Title] = "How to add document properties. It works with DOCX, RTF, PDF, HTML etc";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Company] = "SautinSoft";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Author] = "John Smith";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Subject] = "Document .Net";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Keywords] = "reader, writer, docx, pdf, html, rtf, text";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.HyperlinkBase] = "www.sautinsoft.com";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Manager] = "Alex Dickard";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.Category] = "Document Object Model (DOM)";
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.DateContentCreated] =
                new DateTime(2010, 1, 10).ToString();
            dc.Document.Properties.BuiltIn[BuiltInDocumentProperty.DateLastSaved] =
                DateTime.Now.ToString();

            // Save our document to DOCX format.
            dc.Save(filePath);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }

        /// 
        /// Read built-in document properties (from .docx) and enumerate them in new PDF document as small report.
        /// 
		/// 
        /// Details: https://sautinsoft.com/products/document/examples/document-properties.php
        /// 
        public static void ReadDocumentProperties()
        {
            string inpFile = @"..\..\DocumentProperties.docx";
            string statFile = @"..\..\Statistics.pdf";

            DocumentCore dc = DocumentCore.Load(inpFile);

            // Let's add some additional inforamtion. It can be anything you like.
            dc.Document.Properties.Custom.Add("Producer", "My Producer");

            // Add a paragraph in which all standard information about the document will be stored.
            Paragraph builtInPara = new Paragraph(dc,
            new Run(dc, "Built-in document properties:"),
            new SpecialCharacter(dc, SpecialCharacterType.LineBreak));
            builtInPara.ParagraphFormat.Alignment = HorizontalAlignment.Left;

            foreach (var docProp in dc.Document.Properties.BuiltIn)
            {
                builtInPara.Inlines.Add(
                    new Run(dc, string.Format("{0}: {1}", docProp.Key, docProp.Value)));

                builtInPara.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak));
            }

            // Add a paragraph in which all additional information about the document will be stored.
            Paragraph customPropPara = new Paragraph(dc,
               new Run(dc, "Custom document properties:"),
               new SpecialCharacter(dc, SpecialCharacterType.LineBreak));
            customPropPara.ParagraphFormat.Alignment = HorizontalAlignment.Left;

            foreach (var docProp in dc.Document.Properties.Custom)
            {
                customPropPara.Inlines.Add(
                    new Run(dc, string.Format("{0}: {1} (Type: {2})", docProp.Key, docProp.Value, docProp.Value.GetType())));

                customPropPara.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak));
            }

            // Add all document properties in the document and save it as PDF file.
            dc.Sections.Clear();
            dc.Sections.Add(new Section(dc, builtInPara, customPropPara));

            dc.Save(statFile, new PdfSaveOptions());

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(statFile) { UseShellExecute = true });
        }
    }
}
Option Infer On

Imports System
Imports System.IO
Imports SautinSoft.Document
Imports System.Linq

Module Sample
    Sub Main()
        CreateDocumentProperties()
        ReadDocumentProperties()
    End Sub

    ''' 
    ''' Create a new document (DOCX) with some built-in properties.
    ''' 
    ''' 
    ''' Details: https://sautinsoft.com/products/document/examples/document-properties.php
    ''' 
    Sub CreateDocumentProperties()
        Dim filePath As String = "..\DocumentProperties.docx"

        Dim dc As New DocumentCore()

        ' Let's create a simple inscription.
        dc.Content.End.Insert("Hello World!!!", New CharacterFormat() With {
            .FontName = "Verdana",
            .Size = 65.5F,
            .FontColor = Color.Orange
        })

        ' Let's add some documents properties: Author, Subject, Company.
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Title) = "How to add document properties. It works with DOCX, RTF, PDF, HTML etc"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Company) = "SautinSoft"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Author) = "John Smith"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Subject) = "Document .Net"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Keywords) = "reader, writer, docx, pdf, html, rtf, text"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.HyperlinkBase) = "www.sautinsoft.com"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Manager) = "Alex Dickard"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.Category) = "Document Object Model (DOM)"
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.DateContentCreated) = (New Date(2010, 1, 10)).ToString()
        dc.Document.Properties.BuiltIn(BuiltInDocumentProperty.DateLastSaved) = Date.Now.ToString()

        ' Save our document to DOCX format.
        dc.Save(filePath)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub

    ''' 
    ''' Read built-in document properties (from .docx) and enumerate them in new PDF document as small report.
    ''' 
    ''' 
    ''' Details: https://sautinsoft.com/products/document/examples/document-properties.php
    ''' 
    Sub ReadDocumentProperties()
        Dim inpFile As String = "..\DocumentProperties.docx"
        Dim statFile As String = "..\Statistics.pdf"

        Dim dc As DocumentCore = DocumentCore.Load(inpFile)

        ' Let's add some additional inforamtion. It can be anything you like.
        dc.Document.Properties.Custom.Add("Producer", "My Producer")

        ' Add a paragraph in which all standard information about the document will be stored.
        Dim builtInPara As New Paragraph(dc, New Run(dc, "Built-in document properties:"), New SpecialCharacter(dc, SpecialCharacterType.LineBreak))
        builtInPara.ParagraphFormat.Alignment = HorizontalAlignment.Left

        For Each docProp In dc.Document.Properties.BuiltIn
            builtInPara.Inlines.Add(New Run(dc, String.Format("{0}: {1}", docProp.Key, docProp.Value)))

            builtInPara.Inlines.Add(New SpecialCharacter(dc, SpecialCharacterType.LineBreak))
        Next docProp

        ' Add a paragraph in which all additional information about the document will be stored.
        Dim customPropPara As New Paragraph(dc, New Run(dc, "Custom document properties:"), New SpecialCharacter(dc, SpecialCharacterType.LineBreak))
        customPropPara.ParagraphFormat.Alignment = HorizontalAlignment.Left

        For Each docProp In dc.Document.Properties.Custom
            customPropPara.Inlines.Add(New Run(dc, String.Format("{0}: {1} (Type: {2})", docProp.Key, docProp.Value, docProp.Value.GetType())))

            customPropPara.Inlines.Add(New SpecialCharacter(dc, SpecialCharacterType.LineBreak))
        Next docProp

        ' Add all document properties in the document and save it as PDF file.
        dc.Sections.Clear()
        dc.Sections.Add(New Section(dc, builtInPara, customPropPara))

        dc.Save(statFile, New PdfSaveOptions())

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(statFile) With {.UseShellExecute = True})
    End Sub
End Module

How to find and replace any text content in the document

using System.IO;
using SautinSoft.Document;
using System.Linq;
using System.Text.RegularExpressions;
namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            FindAndReplace();
        }
        /// <summary>
        /// Find and replace a text using ContentRange.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/find-replace-content-net-csharp-vb.php
        /// </remarks>
        public static void FindAndReplace()
        {
            // Path to a loadable document.
            string loadPath = @"..\..\critique.docx";
            // Load a document intoDocumentCore.
            DocumentCore dc = DocumentCore.Load(loadPath);
            Regex regex = new Regex(@"bean", RegexOptions.IgnoreCase);
            //Find "Bean" and Replace everywhere on "Joker :-)"
            // Please note, Reverse() makes sure that action replace not affects to Find().
            foreach (ContentRange item in dc.Content.Find(regex).Reverse())
            {
                item.Replace("Joker");
            }
            // Save our document into PDF format.
            string savePath = "Replaced.pdf";
            dc.Save(savePath, new PdfSaveOptions());
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(loadPath) { UseShellExecute = true });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(savePath) { UseShellExecute = true });
        }
    }
}
                             
Imports System.IO
Imports SautinSoft.Document
Imports System.Linq
Imports System.Text.RegularExpressions
Module Sample
    Sub Main()
        FindAndReplace()
    End Sub
    ''' <summary>
    ''' Find and replace a text using ContentRange.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/find-replace-content-net-csharp-vb.php
    ''' </remarks>
    Sub FindAndReplace()
        ' Path to a loadable document.
        Dim loadPath As String = "..\critique.docx"
        ' Load a document intoDocumentCore.
        Dim dc As DocumentCore = DocumentCore.Load(loadPath)
        Dim regex As New Regex("bean", RegexOptions.IgnoreCase)
        'Find "Bean" and Replace everywhere on "Joker :-)"
        ' Please note, Reverse() makes sure that action replace not affects to Find().
        For Each item As ContentRange In dc.Content.Find(regex).Reverse()
            item.Replace("Joker")
        Next item
        ' Save our document into PDF format.
        Dim savePath As String = "Replaced.pdf"
        dc.Save(savePath, New PdfSaveOptions())
        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(loadPath) With {.UseShellExecute = True})
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(savePath) With {.UseShellExecute = True})
    End Sub
End Module
             

Convert DOCX to PDF format

using System.IO;
using SautinSoft.Document;
namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ConvertFromFile();
            ConvertFromStream();
        }
        /// <summary>
        /// Convert DOCX to PDF (file to file).
        /// </summary>
		/// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/convert-docx-to-pdf-in-csharp-vb.php
        /// </remarks>
        static void ConvertFromFile()
        {
            string inpFile = @"..\..\example.docx";
            string outFile = @"Result.pdf";
            DocumentCore dc = DocumentCore.Load(inpFile);
            dc.Save(outFile);
            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }
        /// <summary>
        /// Convert DOCX to PDF (using Stream).
        /// </summary>
		/// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/convert-docx-to-pdf-in-csharp-vb.php
        /// </remarks>
        static void ConvertFromStream()
        {
            // We need files only for demonstration purposes.
            // The conversion process will be done completely in memory.
            string inpFile = @"..\..\example.docx";
            string outFile = @"ResultStream.pdf";
            byte[] inpData = File.ReadAllBytes(inpFile);
            byte[] outData = null;
            using (MemoryStream msInp = new MemoryStream(inpData))
            {
                // Load a document.
                DocumentCore dc = DocumentCore.Load(msInp, new DocxLoadOptions());
                // Save the document to PDF format.
                using (MemoryStream outMs = new MemoryStream())
                {
                    dc.Save(outMs, new PdfSaveOptions() );
                    outData = outMs.ToArray();                    
                }
                // Show the result for demonstration purposes.
                if (outData != null)
                {
                    File.WriteAllBytes(outFile, outData);
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
                }
            }
        }
    }
}
                             
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
    Sub Main()
        ConvertFromFile()
        ConvertFromStream()
    End Sub
    ''' <summary>
    ''' Convert DOCX to PDF (file to file).
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/convert-docx-to-pdf-in-csharp-vb.php
    ''' </remarks>
    Sub ConvertFromFile()
        Dim inpFile As String = "..\example.docx"
        Dim outFile As String = "Result.pdf"
        Dim dc As DocumentCore = DocumentCore.Load(inpFile)
        dc.Save(outFile)
        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
    End Sub
    ''' <summary>
    ''' Convert DOCX to PDF (using Stream).
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/convert-docx-to-pdf-in-csharp-vb.php
    ''' </remarks>
    Sub ConvertFromStream()
        ' We need files only for demonstration purposes.
        ' The conversion process will be done completely in memory.
        Dim inpFile As String = "..\example.docx"
        Dim outFile As String = "ResultStream.pdf"
        Dim inpData() As Byte = File.ReadAllBytes(inpFile)
        Dim outData() As Byte = Nothing
        Using msInp As New MemoryStream(inpData)
            ' Load a document.
            Dim dc As DocumentCore = DocumentCore.Load(msInp, New DocxLoadOptions())
            ' Save the document to PDF format.
            Using outMs As New MemoryStream()
                dc.Save(outMs, New PdfSaveOptions())
                outData = outMs.ToArray()
            End Using
            ' Show the result for demonstration purposes.
            If outData IsNot Nothing Then
                File.WriteAllBytes(outFile, outData)
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
            End If
        End Using
    End Sub
End Module
             

Technical Support


Technical Support Directly From Our .Net Development Team.

Our high-end technical support guarantees immediate help for all your questions, requirements and technical hitches, whether its product, integration or licensing queries. The SautinSoft product development team are on hand to support all of your questions.

support

Some of our clients


Join these companies that already use Document .NET

IBM
Intel
Cisco
Microsoft
Siemens
Uber
Indiana University – Purdue University Indianapolis
The University of Manchester
New York State
University of Pittsburgh
Western Standard - Translation and Library Technologies
United Graphic Expression Corporation
FoxyUtils
Talent management software
PROS
World Wrestling Entertainment
Moody's Investors Service
Nuance Communications

Sign Up For Newsletter

Contact Us and let us know if you have any questions, Don't forget to subscribe for more awesome stuff by typing mail bellow.

Contact Us:


Phone

BY PHONE

Sweden, Stockholm

+ 46 812111486
support@documentcore.net

Email

Start a new case

Just send us your questions or concerns by starting a new case and we will give you the help you need.

Online chat

Live Chat

Chat with a member of our in-house team.


Сase Number 32

We will answer any your questions and we will give any information on our product within one working day of receipt.

The case number will be sent to the specified email address. In the near future we will contact you and will try to answer your question. If you do not receive a response, please let us know the case number you received.

We'll never share your email with anyone else.