Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.7.18
Syntax Exceptions Exception | Condition |
---|
ArgumentNullException |
Argument start or end is null.
|
ArgumentException |
Arguments start and end do not belong to the same document.
|
Example See Developer Guide: Create a new document with some content
Create a new document with some content using ContentRange in C#
using System.Linq;
using SautinSoft.Document;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
InsertContent();
}
public static void InsertContent()
{
string documentPath = @"InsertContent.pdf";
DocumentCore dc = new DocumentCore();
Section section = new Section(dc);
dc.Sections.Add(section);
section.Blocks.Add(new Paragraph(dc, "This is the first line in 1st paragraph!"));
Paragraph par1 = section.Blocks[0] as Paragraph;
par1.ParagraphFormat.Alignment = HorizontalAlignment.Center;
dc.Content.End.Insert("\nThis is a first line in 2nd paragraph.", new CharacterFormat() { Size = 25, FontColor = Color.Blue, Bold = true });
dc.Content.Start.Insert("Hello from HTML!", new HtmlLoadOptions());
dc.Content.End.Insert(@"{\rtf1 \b The line from RTF\b0!\par}", new RtfLoadOptions());
dc.Content.End.Insert(new SpecialCharacter(dc, SpecialCharacterType.LineBreak).Content);
ContentRange cr = dc.Content.Find("HTML").First();
dc.Content.End.Insert(cr);
Paragraph p = new Paragraph(dc);
Run run = new Run(dc, "As summarize, you can insert content of any class " +
"derived from Element: Table, Shape, Paragraph, Run, HeaderFooter and even a whole DocumentCore!");
run.CharacterFormat.FontColor = Color.DarkGreen;
p.Inlines.Add(run);
dc.Content.End.Insert(p.Content);
dc.Save(documentPath, new PdfSaveOptions() { Compliance = PdfCompliance.PDF_A1a });
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
}
}
}
Create a new document with some content using ContentRange in VB.Net
Imports System
Imports System.IO
Imports System.Linq
Imports SautinSoft.Document
Module Sample
Sub Main()
InsertContent()
End Sub
Sub InsertContent()
Dim documentPath As String = "InsertContent.pdf"
Dim dc As New DocumentCore()
Dim section As New Section(dc)
dc.Sections.Add(section)
section.Blocks.Add(New Paragraph(dc, "This is a first line in 1st paragraph!"))
Dim par1 As Paragraph = TryCast(section.Blocks(0), Paragraph)
par1.ParagraphFormat.Alignment = HorizontalAlignment.Center
dc.Content.End.Insert(vbLf & "This is the first line in 2nd paragraph.", New CharacterFormat() With {
.Size = 25,
.FontColor = Color.Blue,
.Bold = True
})
dc.Content.Start.Insert("Hello from HTML!", New HtmlLoadOptions())
dc.Content.End.Insert("{\rtf1 \b The line from RTF\b0!\par}", New RtfLoadOptions())
dc.Content.End.Insert((New SpecialCharacter(dc, SpecialCharacterType.LineBreak)).Content)
Dim cr As ContentRange = dc.Content.Find("HTML").First()
dc.Content.End.Insert(cr)
Dim p As New Paragraph(dc)
Dim run As New Run(dc, "As summarize, you can insert content of any class " & "derived from Element: Table, Shape, Paragraph, Run, HeaderFooter and even a whole DocumentCore!")
run.CharacterFormat.FontColor = Color.DarkGreen
p.Inlines.Add(run)
dc.Content.End.Insert(p.Content)
dc.Save(documentPath, New PdfSaveOptions() With {.Compliance = PdfCompliance.PDF_A1a})
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
End Sub
End Module
See Also