// The file format will be detected automatically from the file extension: ".pdf".
dc.Save(@"d:\Book.pdf");
To not rely on the file extension and guarantee that the file contents is really PDF (Adobe Portable Format), you may specify PdfSaveOptions as 2nd parameter.
dc.Save(@"d:\Book.pdf", new PdfSaveOptions());
In PdfSaveOptions you can also set various options which affects to the saving process.
dc.Save(@"d:\Book.pdf", new PdfSaveOptions()
{
Compliance = PdfCompliance.PDF_A,
PreserveFormFields = true
});
// 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
});
}
using System.IO;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
SaveToPdfFile();
SaveToPdfStream();
}
static void SaveToPdfFile()
{
// Assume we already have a document 'dc'.
DocumentCore dc = new DocumentCore();
dc.Content.End.Insert("Hey Guys and Girls!");
string filePath = @"Result-file.pdf";
dc.Save(filePath, new PdfSaveOptions()
{
Compliance = PdfCompliance.PDF_A,
PreserveFormFields = true
});
}
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!");
// 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);
}
}
}
Imports System.IO
Imports SautinSoft.Document
Module ExampleVB
Sub Main()
SaveToPdfFile()
SaveToPdfStream()
End Sub
Public Sub SaveToPdfFile()
' Assume we already have a document 'dc'.
Dim dc As New DocumentCore()
dc.Content.End.Insert("Hey Guys and Girls!")
Dim filePath As String = "Result-file.pdf"
dc.Save(filePath, New PdfSaveOptions() With {
.Compliance = PdfCompliance.PDF_A,
.PreserveFormFields = True
})
End Sub
Public 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!")
' 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)
End Sub
End Module