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.

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.
Developer-friendly
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/help/net/developer-guide/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/help/net/developer-guide/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/help/net/developer-guide/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/help/net/developer-guide/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;
using SautinSoft.Document.Drawing;
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Here we'll show two ways to create PDF document from a scratch.
// Use any of them, which is more clear to you.
// 1. With help of DocumentBuilder (wizard).
CreatePdfUsingDocumentBuilder();
// 2. With Document Object Model (DOM) directly.
CreatePdfUsingDOM();
}
/// <summary>
/// Creates a new PDF document using DocumentBuilder wizard.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-pdf-document-net-csharp-vb.php
/// </remarks>
public static void CreatePdfUsingDocumentBuilder()
{
// Set a path to our document.
string docPath = @"Result-DocumentBuilder.pdf";
// Create a new document and DocumentBuilder.
DocumentCore dc = new DocumentCore();
DocumentBuilder db = new DocumentBuilder(dc);
// Set page size A4.
Section section = db.Document.Sections[0];
section.PageSetup.PaperType = PaperType.A4;
// Add 1st paragraph with formatted text.
db.CharacterFormat.FontName = "Verdana";
db.CharacterFormat.Size = 16;
db.CharacterFormat.FontColor = Color.Orange;
db.Write("This is a first line in 1st paragraph!");
// Add a line break into the 1st paragraph.
db.InsertSpecialCharacter(SpecialCharacterType.LineBreak);
// Add 2nd line to the 1st paragraph, create 2nd paragraph.
db.Writeln("Let's type a second line.");
// Specify the paragraph alignment.
(section.Blocks[0] as Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center;
// Add text into the 2nd paragraph.
db.CharacterFormat.ClearFormatting();
db.CharacterFormat.Size = 25;
db.CharacterFormat.FontColor = Color.Blue;
db.CharacterFormat.Bold = true;
db.Write("This is a first line in 2nd paragraph.");
// Insert a line break into the 2nd paragraph.
db.InsertSpecialCharacter(SpecialCharacterType.LineBreak);
// Insert 2nd line with own formatting to the 2nd paragraph.
db.CharacterFormat.Size = 20;
db.CharacterFormat.FontColor = Color.DarkGreen;
db.CharacterFormat.UnderlineStyle = UnderlineType.Single;
db.CharacterFormat.Bold = false;
db.Write("This is a second line.");
// Add a graphics figure into the paragraph.
db.CharacterFormat.ClearFormatting();
Shape shape = db.InsertShape(SautinSoft.Document.Drawing.Figure.SmileyFace, new SautinSoft.Document.Drawing.Size(50, 50, LengthUnit.Millimeter));
// Specify outline and fill.
shape.Outline.Fill.SetSolid(new SautinSoft.Document.Color("#358CCB"));
shape.Outline.Width = 3;
shape.Fill.SetSolid(SautinSoft.Document.Color.Orange);
// Save the document to the file in PDF format.
dc.Save(docPath, new PdfSaveOptions()
{ Compliance = PdfCompliance.PDF_A1a });
// Open the result for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docPath) { UseShellExecute = true });
}
/// <summary>
/// Creates a new PDF document using DOM directly.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-pdf-document-net-csharp-vb.php
/// </remarks>
public static void CreatePdfUsingDOM()
{
// Set a path to our document.
string docPath = @"Result-DocumentCore.pdf";
// Create a new 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
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 run1 = new Run(dc, "This is a first line in 1st paragraph!");
run1.CharacterFormat = cf;
par1.Inlines.Add(run1);
// Let's add a line break into the 1st paragraph.
par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak));
// Copy the formatting.
Run run2 = run1.Clone();
run2.Text = "Let's type a second line.";
par1.Inlines.Add(run2);
// Add 2nd paragraph.
Paragraph par2 = new Paragraph(dc, new Run(dc, "This is a first line in 2nd paragraph.", new CharacterFormat() { Size = 25, FontColor = Color.Blue, Bold = true }));
section.Blocks.Add(par2);
SpecialCharacter lBr = new SpecialCharacter(dc, SpecialCharacterType.LineBreak);
par2.Inlines.Add(lBr);
Run run3 = new Run(dc, "This is a second line.", new CharacterFormat() { Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single });
par2.Inlines.Add(run3);
// Add a graphics figure into the paragraph.
Shape shape = new Shape(dc, new InlineLayout(new SautinSoft.Document.Drawing.Size(50, 50, LengthUnit.Millimeter)));
// Specify outline and fill.
shape.Outline.Fill.SetSolid(new SautinSoft.Document.Color("#358CCB"));
shape.Outline.Width = 3;
shape.Fill.SetSolid(SautinSoft.Document.Color.Orange);
shape.Geometry.SetPreset(Figure.SmileyFace);
par2.Inlines.Add(shape);
// Save the document to the file in PDF format.
dc.Save(docPath, new PdfSaveOptions()
{ Compliance = PdfCompliance.PDF_A1a });
// Open the result for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docPath) { UseShellExecute = true });
}
}
}
Imports SautinSoft.Document
Imports SautinSoft.Document.Drawing
Namespace Example
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Here we'll show two ways to create PDF document from a scratch.
' Use any of them, which is more clear to you.
' 1. With help of DocumentBuilder (wizard).
CreatePdfUsingDocumentBuilder()
' 2. With Document Object Model (DOM) directly.
CreatePdfUsingDOM()
End Sub
''' <summary>
''' Creates a new PDF document using DocumentBuilder wizard.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-pdf-document-net-csharp-vb.php
''' </remarks>
Public Shared Sub CreatePdfUsingDocumentBuilder()
' Set a path to our document.
Dim docPath As String = "Result-DocumentBuilder.pdf"
' Create a new document and DocumentBuilder.
Dim dc As New DocumentCore()
Dim db As New DocumentBuilder(dc)
' Set page size A4.
Dim section As Section = db.Document.Sections(0)
section.PageSetup.PaperType = PaperType.A4
' Add 1st paragraph with formatted text.
db.CharacterFormat.FontName = "Verdana"
db.CharacterFormat.Size = 16
db.CharacterFormat.FontColor = Color.Orange
db.Write("This is a first line in 1st paragraph!")
' Add a line break into the 1st paragraph.
db.InsertSpecialCharacter(SpecialCharacterType.LineBreak)
' Add 2nd line to the 1st paragraph, create 2nd paragraph.
db.Writeln("Let's type a second line.")
' Specify the paragraph alignment.
TryCast(section.Blocks(0), Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center
' Add text into the 2nd paragraph.
db.CharacterFormat.ClearFormatting()
db.CharacterFormat.Size = 25
db.CharacterFormat.FontColor = Color.Blue
db.CharacterFormat.Bold = True
db.Write("This is a first line in 2nd paragraph.")
' Insert a line break into the 2nd paragraph.
db.InsertSpecialCharacter(SpecialCharacterType.LineBreak)
' Insert 2nd line with own formatting to the 2nd paragraph.
db.CharacterFormat.Size = 20
db.CharacterFormat.FontColor = Color.DarkGreen
db.CharacterFormat.UnderlineStyle = UnderlineType.Single
db.CharacterFormat.Bold = False
db.Write("This is a second line.")
' Add a graphics figure into the paragraph.
db.CharacterFormat.ClearFormatting()
Dim shape As Shape = db.InsertShape(SautinSoft.Document.Drawing.Figure.SmileyFace, New SautinSoft.Document.Drawing.Size(50, 50, LengthUnit.Millimeter))
' Specify outline and fill.
shape.Outline.Fill.SetSolid(New SautinSoft.Document.Color("#358CCB"))
shape.Outline.Width = 3
shape.Fill.SetSolid(SautinSoft.Document.Color.Orange)
' Save the document to the file in PDF format.
dc.Save(docPath, New PdfSaveOptions() With {.Compliance = PdfCompliance.PDF_A1a})
' Open the result for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docPath) With {.UseShellExecute = True})
End Sub
''' <summary>
''' Creates a new PDF document using DOM directly.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-pdf-document-net-csharp-vb.php
''' </remarks>
Public Shared Sub CreatePdfUsingDOM()
' Set a path to our document.
Dim docPath As String = "Result-DocumentCore.pdf"
' Create a new 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
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 run1 As New Run(dc, "This is a first line in 1st paragraph!")
run1.CharacterFormat = cf
par1.Inlines.Add(run1)
' Let's add a line break into the 1st paragraph.
par1.Inlines.Add(New SpecialCharacter(dc, SpecialCharacterType.LineBreak))
' Copy the formatting.
Dim run2 As Run = run1.Clone()
run2.Text = "Let's type a second line."
par1.Inlines.Add(run2)
' Add 2nd paragraph.
Dim par2 As Paragraph = New Paragraph(dc, New Run(dc, "This is a first line in 2nd paragraph.", New CharacterFormat() With {
.Size = 25,
.FontColor = Color.Blue,
.Bold = True
}))
section.Blocks.Add(par2)
Dim lBr As New SpecialCharacter(dc, SpecialCharacterType.LineBreak)
par2.Inlines.Add(lBr)
Dim run3 As Run = New Run(dc, "This is a second line.", New CharacterFormat() With {
.Size = 20,
.FontColor = Color.DarkGreen,
.UnderlineStyle = UnderlineType.Single
})
par2.Inlines.Add(run3)
' Add a graphics figure into the paragraph.
Dim shape As New Shape(dc, New InlineLayout(New SautinSoft.Document.Drawing.Size(50, 50, LengthUnit.Millimeter)))
' Specify outline and fill.
shape.Outline.Fill.SetSolid(New SautinSoft.Document.Color("#358CCB"))
shape.Outline.Width = 3
shape.Fill.SetSolid(SautinSoft.Document.Color.Orange)
shape.Geometry.SetPreset(Figure.SmileyFace)
par2.Inlines.Add(shape)
' Save the document to the file in PDF format.
dc.Save(docPath, New PdfSaveOptions() With {.Compliance = PdfCompliance.PDF_A1a})
' Open the result for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docPath) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
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/help/net/developer-guide/merge-multiple-files-net-csharp-vb.php
/// </remarks>
public static void MergeMultipleDocuments()
{
// Path to our combined document.
string singlePDFPath = "Single.pdf";
string workingDir = @"..\..\";
List supportedFiles = new List();
// 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(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/help/net/developer-guide/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/help/net/developer-guide/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_A1a,
PaginatorOptions = new PaginatorOptions()
{
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/help/net/developer-guide/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_A1a
});
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/help/net/developer-guide/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_A1a,
.PaginatorOptions = New PaginatorOptions() With {.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/help/net/developer-guide/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_A1a
})
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();
}
/// <summary>
/// Loads an HTML document into DocumentCore (dc) from a file.
/// </summary>
/// <remarks>
/// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/load-html-document-net-csharp-vb.php
/// </remarks>
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();
}
/// <summary>
/// Loads an HTML document into DocumentCore (dc) from a MemoryStream.
/// </summary>
/// <remarks>
/// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/load-html-document-net-csharp-vb.php
/// </remarks>
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
''' <summary>
''' Loads an HTML document into DocumentCore (dc) from a file.
''' </summary>
''' <remarks>
''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/load-html-document-net-csharp-vb.php
''' </remarks>
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
''' <summary>
''' Loads an HTML document into DocumentCore (dc) from a MemoryStream.
''' </summary>
''' <remarks>
''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/load-html-document-net-csharp-vb.php
''' </remarks>
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();
}
/// <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/help/net/developer-guide/digital-signature-net-csharp-vb.php
/// </remarks>
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/help/net/developer-guide/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();
}
/// <summary>
/// Create a new document (DOCX) with some built-in properties.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/document-properties.php
/// </remarks>
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 });
}
/// <summary>
/// Read built-in document properties (from .docx) and enumerate them in new PDF document as small report.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/document-properties.php
/// </remarks>
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
''' <summary>
''' Create a new document (DOCX) with some built-in properties.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/document-properties.php
''' </remarks>
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
''' <summary>
''' Read built-in document properties (from .docx) and enumerate them in new PDF document as small report.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/document-properties.php
''' </remarks>
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/help/net/developer-guide/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/help/net/developer-guide/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
How to add Header and Footer in PDF file
using System.IO;
using SautinSoft.Document;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
AddHeaderFooter();
}
/// <summary>
/// How to add a header and footer into PDF document.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-header-and-footer-in-pdf-net-csharp-vb.php
/// </remarks>
static void AddHeaderFooter()
{
string inpFile = @"..\..\shrek.pdf";
string outFile = "Shrek with header and footer.pdf";
DocumentCore dc = DocumentCore.Load(inpFile);
// Create new header with formatted text.
HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);
header.Content.Start.Insert("Shrek and Donkey", new CharacterFormat() { Size = 14.0, FontColor = Color.Brown });
foreach (Section s in dc.Sections)
{
s.HeadersFooters.Add(header.Clone(true));
}
// Create new footer with formatted text.
HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);
footer.Content.Start.Insert("Fiona.", new CharacterFormat() { Size = 14.0, FontColor = Color.Blue });
foreach (Section s in dc.Sections)
{
s.HeadersFooters.Add(footer.Clone(true));
}
dc.Save(outFile);
// Open the PDF documents for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(inpFile) { UseShellExecute = true });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
}
}
}
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
AddHeaderFooter()
End Sub
''' <summary>
''' How to add a header and footer into PDF document.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/add-header-and-footer-in-pdf-net-csharp-vb.php
''' </remarks>
Sub AddHeaderFooter()
Dim inpFile As String = "..\shrek.pdf"
Dim outFile As String = "Shrek with header and footer.pdf"
Dim dc As DocumentCore = DocumentCore.Load(inpFile)
' Create new header with formatted text.
Dim header As New HeaderFooter(dc, HeaderFooterType.HeaderDefault)
header.Content.Start.Insert("Shrek and Donkey", New CharacterFormat() With {
.Size = 14.0,
.FontColor = Color.Brown
})
For Each s As Section In dc.Sections
s.HeadersFooters.Add(header.Clone(True))
Next s
' Create new footer with formatted text.
Dim footer As New HeaderFooter(dc, HeaderFooterType.FooterDefault)
footer.Content.Start.Insert("Fiona.", New CharacterFormat() With {
.Size = 14.0,
.FontColor = Color.Blue
})
For Each s As Section In dc.Sections
s.HeadersFooters.Add(footer.Clone(True))
Next s
dc.Save(outFile)
' Open the PDF documents for demonstration purposes.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(inpFile) With {.UseShellExecute = True})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) 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/help/net/developer-guide/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/help/net/developer-guide/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/help/net/developer-guide/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/help/net/developer-guide/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.

Some of our clients
Join these companies that already use Document .NET


















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.