Class PdfDocumentBase
Represent common properties of PdfDocument and PdfLoadedDocument classes.
Inherited Members
Namespace: Syncfusion.Pdf
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public abstract class PdfDocumentBase
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Set the document`s viewer preference
doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft;
doc.ViewerPreferences.PageScaling = PageScalingMode.AppDefault;
doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;
doc.Save("ViewerPreferences.pdf");
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Set the document`s viewer preference
doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft
doc.ViewerPreferences.PageScaling = PageScalingMode.AppDefault
doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen
doc.Save("ViewerPreferences.pdf")
'Close the document
doc.Close(True)
Constructors
PdfDocumentBase()
Declaration
protected PdfDocumentBase()
Properties
BaseUri
Gets or sets the Base URI of the PDF document.
Declaration
public string BaseUri { get; set; }
Property Value
Type |
---|
System.String |
Examples
//Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
//Set the Base URI.
document.BaseUri = "https://www.syncfusion.com/";
//Create a new page.
PdfPage page = document.Pages.Add();
//Save the document.
document.Save("Output.pdf");
//Close the document.
document.Close(true);
'Create a new instance of PdfDocument class.
Dim document As PdfDocument = New PdfDocument()
'Set the Base URI.
document.BaseUri = "https://www.syncfusion.com/"
'Create a new page.
Dim page As PdfPage = document.Pages.Add()
'Save the document.
document.Save("Output.pdf")
'Close the document.
document.Close(True)
See Also
Bookmarks
Gets the bookmarks.
Declaration
public abstract PdfBookmarkBase Bookmarks { get; }
Property Value
Type |
---|
PdfBookmarkBase |
Remarks
To know more about refer this link .
Examples
//Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
//Add the section.
PdfSection sec = document.Sections.Add();
//Add pages to the section.
PdfPage page = document.Pages.Add();
//Get boookmarks from pdf document.
PdfBookmarkBase outlines = document.Bookmarks;
//Add new bookmark.
PdfBookmark bookmark = outlines.Add("Section");
for (int i = 0; i != 5; i++)
{
//Add pages to the section.
page = sec.Pages.Add();
//Add new bookmark.
bookmark.Add("Page" + i);
//Set the destination for the created bookmark.
bookmark.Destination = new PdfDestination(page);
}
//Save and close the pdf document.
document.Save("Output.pdf");
document.Close(true);
'Create a new instance of PdfDocument class.
Dim document As PdfDocument = New PdfDocument()
'Add the section.
Dim sec As PdfSection = document.Sections.Add()
'Add pages to the section.
Dim page As PdfPage = document.Pages.Add()
'Get boookmarks from pdf document.
Dim outlines As PdfBookmarkBase = document.Bookmarks
'Add new bookmark.
Dim bookmark As PdfBookmark = outlines.Add("Section")
For i As Integer = 0 To 5 - 1
page = sec.Pages.Add()
bookmark.Add("Page" + i)
bookmark.Destination = New PdfDestination(page)
Next
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Compression
Gets or sets the PDF document compression level. By default the compression level is None
Declaration
public PdfCompressionLevel Compression { get; set; }
Property Value
Type |
---|
PdfCompressionLevel |
Remarks
To know more about refer this link .
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Set the document`s compression level.
doc.Compression = PdfCompressionLevel.Best;
//Creates a new page
PdfPage page = doc.Pages.Add();
doc.Save("Compression.pdf");
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Set the document`s compression level.
doc.Compression = PdfCompressionLevel.Best
'Create a page.
Dim page As PdfPage = doc.Pages.Add()
doc.Save("Compression.pdf")
'Close the document.
doc.Close(True)
See Also
DocumentInformation
Gets or sets document's information and properties such as document's title, subject, keyword etc.
Declaration
public virtual PdfDocumentInformation DocumentInformation { get; }
Property Value
Type |
---|
PdfDocumentInformation |
Remarks
To know more about refer this link .
Examples
//Create new pdf document.
PdfDocument document = new PdfDocument();
//Set the document author property.
document.DocumentInformation.Author = "Syncfusion";
//Get the document author property value.
string author = document.DocumentInformation.Author;
//Save and close the document.
document.Save("output.pdf");
document.Close(true);
//Load an existing document.
PdfLoadedDocument ldoc = new PdfLoadedDocument("output.pdf");
//Get the loaded document author property value.
author = ldoc.DocumentInformation.Author;
//Save and close the document.
ldoc.Save("output.pdf");
ldoc.Close(true);
'Create new pdf document.
Dim document As PdfDocument = New PdfDocument()
'Set the document author property.
document.DocumentInformation.Author = "Syncfusion"
'Get the document author property value.
Dim author As String = document.DocumentInformation.Author
'Save and close the document.
document.Save("output.pdf")
document.Close(True)
'Load an existing document.
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument("output.pdf")
'Get the loaded document author property value.
author = ldoc.DocumentInformation.Author
'Save and close the document.
ldoc.Save("output.pdf")
ldoc.Close(True)
See Also
EnableMemoryOptimization
Gets or sets whether to optimize memory.
Declaration
public bool EnableMemoryOptimization { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Optimization will be effective only with merge, append and import functions. Only memory will be optimized, different in time occur based on the document size.
Examples
//Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
//Enable memory optimization.
document.EnableMemoryOptimization = true;
//Merge source document
PdfDocument.Merge(document, "Source.pdf");
//Save and close the pdf document.
document.Save("Output.pdf");
document.Close(true);
'Create a new PDF document.
Dim document As PdfDocument = New PdfDocument()
'Enable memory optimization.
document.EnableMemoryOptimization = True
'Merge source document.
PdfDocument.Merge(document, "Source.pdf")
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
FileStructure
Gets or sets the internal structure of the PDF document.
Declaration
public PdfFileStructure FileStructure { get; set; }
Property Value
Type |
---|
PdfFileStructure |
Examples
//Create a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
// Set the document`s cross reference Type
doc.FileStructure.CrossReferenceType = PdfCrossReferenceType.CrossReferenceStream;
// Set the pdf version
doc.FileStructure.Version = PdfVersion.Version1_6;
// Save the document
doc.Save("FileStructure.pdf");
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
' Set the document`s cross reference Type
doc.FileStructure.CrossReferenceType = PdfCrossReferenceType.CrossReferenceStream
' set the pdf version
doc.FileStructure.Version = PdfVersion.Version1_6
' Save the document
doc.Save("FileStructure.pdf")
See Also
Layers
Gets the collection of PdfLayer from the PDF document
Declaration
public PdfDocumentLayerCollection Layers { get; }
Property Value
Type |
---|
PdfDocumentLayerCollection |
PortfolioInformation
Gets or sets the portfolio information to the Document.
Declaration
public PdfPortfolioInformation PortfolioInformation { get; set; }
Property Value
Type |
---|
PdfPortfolioInformation |
Remarks
To know more about refer this link .
Examples
// Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
//Creating new portfolio
document.PortfolioInformation = new PdfPortfolioInformation();
//setting the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile;
//Creating the attachment
PdfAttachment pdfFile = new PdfAttachment("Input.pdf");
pdfFile.FileName = "EmployeeDetails.pdf";
//Setting the startup document to view
document.PortfolioInformation.StartupDocument = pdfFile;
//Adding the attachment into document
document.Attachments.Add(pdfFile);
// Save and close the document.
document.Save("Output.pdf");
document.Close(true);
'Create a new instance of PdfDocument class.
Dim document As New PdfDocument()
'Creating new portfolio
document.PortfolioInformation = New PdfPortfolioInformation()
'setting the view mode of the portfolio
document.PortfolioInformation.ViewMode = PdfPortfolioViewMode.Tile
'Creating the attachment
Dim pdfFile As New PdfAttachment("Input.pdf")
pdfFile.FileName = "EmployeeDetails.pdf"
'Setting the startup document to view
document.PortfolioInformation.StartupDocument = pdfFile
'Adding the attachment into document
document.Attachments.Add(pdfFile)
'Save and close the document.
document.Save("Output.pdf")
document.Close(True)
See Also
Security
Gets the security features of the document like encryption.
Declaration
public PdfSecurity Security { get; }
Property Value
Type |
---|
PdfSecurity |
Remarks
To know more about refer this link .
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
// Reading security settings of the document
PdfSecurity security = doc.Security;
doc.Save("Security.pdf");
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
' Reading security settings of the document
Dim security As PdfSecurity = doc.Security
doc.Save("Security.pdf")
'Close the document
doc.Close(True)
See Also
ViewerPreferences
Gets or sets a viewer preferences. This property is used for presenting the PDF document in a viewer.
Declaration
public PdfViewerPreferences ViewerPreferences { get; set; }
Property Value
Type |
---|
PdfViewerPreferences |
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Set the document`s viewer preference
doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft;
doc.ViewerPreferences.PageScaling = PageScalingMode.AppDefault;
doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;
doc.Save("ViewerPreferences.pdf");
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Set the document`s viewer preference
doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft
doc.ViewerPreferences.PageScaling = PageScalingMode.AppDefault
doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen
doc.Save("ViewerPreferences.pdf")
'Close the document
doc.Close(True)
See Also
Methods
Append(PdfLoadedDocument)
Appends the loaded document given as parameter to the current document.
Declaration
public void Append(PdfLoadedDocument ldDoc)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document to be imported. |
Remarks
The appended loaded document must remain open until the current document is saved.
Examples
// Source document
PdfLoadedDocument srcDoc = new PdfLoadedDocument("SrcDocument.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
// Appending the document with source document.
doc.Append(srcDoc);
// Save the document.
doc.Save("Append.pdf");
//close both the instance
doc.Close(true);
srcDoc.Close(true);
' Source document
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("SrcDocument.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
' Appending the document with source document.
doc.Append(srcDoc)
' Save the document.
doc.Save("Append.pdf")
'Close bothe the instance
doc.Close(True)
srcDoc.Close(True)
See Also
CheckFields(PdfLoadedDocument, PdfPageBase, List<PdfField>, PdfPageBase)
Checks form fields are connected with the page.
Declaration
protected virtual void CheckFields(PdfLoadedDocument ldDoc, PdfPageBase page, List<PdfField> fields, PdfPageBase importedPage)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document. |
PdfPageBase | page | The page. |
System.Collections.Generic.List<PdfField> | fields | An array where the fields connected to the page are stored. |
PdfPageBase | importedPage |
Close()
Closes the document. Releases all common resources.
Declaration
public void Close()
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
//Save the document
doc.Save("Close.pdf");
//Close the document
doc.Close();
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
'Save the document
doc.Save("Close.pdf")
' Closes the document
doc.Close()
See Also
Close(Boolean)
Closes the document.
Declaration
public virtual void Close(bool completely)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | completely | if set to |
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
//Save the document
doc.Save("Close.pdf");
// Closes the document completely.
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
'Save the document
doc.Save("Close.pdf")
' Closes the document completely.
doc.Close(True)
See Also
DisposeOnClose(IDisposable)
Adds an object to a collection of the objects that will be disposed during document closing.
Declaration
public void DisposeOnClose(IDisposable obj)
Parameters
Type | Name | Description |
---|---|---|
System.IDisposable | obj | The object that will be disposed during document closing. |
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
Image img = Image.FromFile("input.png");
PdfImage pdfImg = new PdfBitmap(img);
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
doc.Save("DisposeOnClose.pdf");
// Dispose the Img object along with the document.
doc.DisposeOnClose(img);
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim img As Image = Image.FromFile("Logo.png")
Dim pdfImg As PdfImage = New PdfBitmap(img)
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
doc.Save("DisposeOnClose.pdf")
' Dispose the Img object along with the document.
doc.DisposeOnClose(img)
'Close the document
doc.Close(True)
See Also
ImportPage(PdfLoadedDocument, PdfPageBase)
Imports the specified page into the current document pages collection
Declaration
public PdfPageBase ImportPage(PdfLoadedDocument ldDoc, PdfPageBase page)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document to be imported. |
PdfPageBase | page | The page to be inserted. |
Returns
Type | Description |
---|---|
PdfPageBase | The page in the target document. |
Remarks
The loaded document must remain open until the current document is saved
Examples
// Source document
PdfLoadedDocument srcDoc = new PdfLoadedDocument("SrcDocument.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
// Importing pages from source document.
doc.ImportPage(srcDoc, srcDoc.Pages[0]);
doc.Save("ImportPages.pdf");
//Close both the instance
doc.Close(true);
srcDoc.Close(true);
' Source document
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("SrcDocument.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
' Importing pages from source document.
doc.ImportPage(srcDoc, srcDoc.Pages(0))
doc.Save("ImportPages.pdf")
'Close both the instance
doc.Close(True)
srcDoc.Close(True)
See Also
ImportPage(PdfLoadedDocument, Int32)
Imports the loaded document's page index to the current document.
Declaration
public PdfPageBase ImportPage(PdfLoadedDocument ldDoc, int pageIndex)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document to be imported. |
System.Int32 | pageIndex | Index of the page. |
Returns
Type | Description |
---|---|
PdfPageBase | The page in the target document. |
Remarks
The loaded document must remain open until the current document is saved
Examples
// Source document
PdfLoadedDocument srcDoc = new PdfLoadedDocument("SrcDocument.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
// Importing pages from source document.
doc.ImportPage(srcDoc, 0);
doc.Save("ImportPages.pdf");
//Close both the instance
doc.Close(true);
srcDoc.Close(true);
' Source document
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("SrcDocument.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
' Importing pages from source document.
doc.ImportPage(srcDoc, 0)
doc.Save("ImportPages.pdf")
'Close both the instance
doc.Close(True)
srcDoc.Close(True)
See Also
ImportPageRange(PdfLoadedDocument, Int32, Int32)
Imports a page range from a loaded document to the current document
Declaration
public PdfPageBase ImportPageRange(PdfLoadedDocument ldDoc, int startIndex, int endIndex)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document to be imported. |
System.Int32 | startIndex | The start page index. |
System.Int32 | endIndex | The end page index. |
Returns
Type | Description |
---|---|
PdfPageBase | The last created page in the target document. |
Remarks
The loaded document must remain open until the current document is saved
Examples
// Source document
PdfLoadedDocument srcDoc = new PdfLoadedDocument("SrcDocument.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
// Importing pages from source document.
doc.ImportPageRange(srcDoc, 0, 2);
doc.Save("ImportPages.pdf");
//Close both the instance
doc.Close(true);
srcDoc.Close(true);
' Source document
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("SrcDocument.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
' Importing pages from source document.
doc.ImportPageRange(srcDoc, 0, 2)
doc.Save("ImportPages.pdf")
'Close both the instance
doc.Close(True)
srcDoc.Close(True)
See Also
ImportPageRange(PdfLoadedDocument, Int32, Int32, Boolean)
Imports a page range from a loaded document to the current document
Declaration
public PdfPageBase ImportPageRange(PdfLoadedDocument ldDoc, int startIndex, int endIndex, bool importBookmarks)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedDocument | ldDoc | The loaded document to be imported. |
System.Int32 | startIndex | The start page index. |
System.Int32 | endIndex | The end page index. |
System.Boolean | importBookmarks | Gets value whether to import bookmarks from the imported page. |
Returns
Type | Description |
---|---|
PdfPageBase | The last created page in the target document. |
Remarks
The loaded document must remain open until the current document is saved
Examples
// Source document
PdfLoadedDocument srcDoc = new PdfLoadedDocument("SrcDocument.pdf");
//Create a new document.
PdfDocument doc = new PdfDocument();
// Importing pages from source document without bookmarks.
doc.ImportPageRange(srcDoc, 0, 2, false);
doc.Save("ImportPages.pdf");
//Close both the instance
doc.Close(true);
srcDoc.Close(true);
' Source document
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("SrcDocument.pdf")
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
' Importing pages from source document.
doc.ImportPageRange(srcDoc, 0, 2, true)
doc.Save("ImportPages.pdf")
'Close both the instance
doc.Close(True)
srcDoc.Close(True)
Merge(PdfDocumentBase, PdfLoadedDocument)
Merges the specified dest.
Declaration
public static PdfDocumentBase Merge(PdfDocumentBase dest, PdfLoadedDocument src)
Parameters
Type | Name | Description |
---|---|---|
PdfDocumentBase | dest | The destination document. |
PdfLoadedDocument | src | The source document. |
Returns
Type | Description |
---|---|
PdfDocumentBase | The merged document |
Examples
// Source document.
PdfLoadedDocument srcDoc = new PdfLoadedDocument("Src1.pdf");
// Destination PDF document
PdfDocument destDoc = new PdfDocument();
//Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, srcDoc);
destDoc.Save("Merge.pdf");
' Source document.
Dim srcDoc As PdfLoadedDocument = New PdfLoadedDocument("Src1.pdf")
' Destination PDF document
Dim destDoc As PdfDocument = New PdfDocument()
'Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, srcDoc)
destDoc.Save("Merge.pdf")
See Also
Merge(PdfDocumentBase, PdfMergeOptions, Object[])
Merges the specified source documents with PdfMergeOptions and return destination document.
Declaration
public static PdfDocumentBase Merge(PdfDocumentBase dest, PdfMergeOptions options, params object[] sourceDocuments)
Parameters
Type | Name | Description |
---|---|---|
PdfDocumentBase | dest | The destination document, where the other documents are merged into. If it's null a new document object will be created. |
PdfMergeOptions | options | customize the merging PDF. |
System.Object[] | sourceDocuments | The source documents. |
Returns
Type | Description |
---|---|
PdfDocumentBase | The options contain Optimizing resources. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
// Destination PDF document
PdfDocument destDoc = new PdfDocument();
// Source PDF documents
string[] source = { "Src1.pdf", "Src2.pdf" };
PdfMergeOptions option = new PdfMergeOptions();
option.OptimizeResources = true;
//Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, option, source);
destDoc.Save("Merge.pdf");
' Destination PDF document
Dim destDoc As PdfDocument = New PdfDocument()
' Source PDF documents
Dim [option] As PdfMergeOptions = New PdfMergeOptions()
[option].OptimizeResources = True
PdfDocumentBase.Merge(destDoc, [option], source)
'Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, source)
destDoc.Save("Merge.pdf")
See Also
Merge(PdfDocumentBase, Object[])
Merges the specified source documents and return destination document.
Declaration
public static PdfDocumentBase Merge(PdfDocumentBase dest, params object[] sourceDocuments)
Parameters
Type | Name | Description |
---|---|---|
PdfDocumentBase | dest | The destination document, where the other documents are merged into. If it's null a new document object will be created. |
System.Object[] | sourceDocuments | The source documents. |
Returns
Type | Description |
---|---|
PdfDocumentBase | The document containing merged documents. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
// Destination PDF document
PdfDocument destDoc = new PdfDocument();
// Source PDF documents
string[] source = { "Src1.pdf", "Src2.pdf" };
//Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, source);
destDoc.Save("Merge.pdf");
' Destination PDF document
Dim destDoc As PdfDocument = New PdfDocument()
' Source PDF documents
Dim source() As String = { "Src1.pdf", "Src2.pdf" }
'Merge the source pdf document.
PdfDocumentBase.Merge(destDoc, source)
destDoc.Save("Merge.pdf")
See Also
Merge(String[])
Merges the PDF documents specified by the paths.
Declaration
public static PdfDocument Merge(string[] paths)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | paths | The array of string paths. |
Returns
Type | Description |
---|---|
PdfDocument | A new PDF document containing all merged documents. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
// Destination PDF document
PdfDocument destDoc = new PdfDocument();
// Source PDF documents
string[] source = { "Src1.pdf", "Src2.pdf" };
//Merge the source pdf document.
destDoc = PdfDocument.Merge(source);
destDoc.Save("Merge.pdf");
' Destination PDF document
Dim destDoc As PdfDocument = New PdfDocument()
' Source PDF documents
Dim source() As String = { "Src1.pdf", "Src2.pdf" }
'Merge the source pdf document.
destDoc = PdfDocument.Merge(source)
destDoc.Save("Merge.pdf")
See Also
Merge(String[], PdfMergeOptions)
Merges the PDF documents specified by the paths with PdfMergeOptions.
Declaration
public static PdfDocument Merge(string[] paths, PdfMergeOptions options)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | paths | The array of string paths. |
PdfMergeOptions | options | customize the merging PDF. |
Returns
Type | Description |
---|---|
PdfDocument | A new PDF document containing all merged documents. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
// Destination PDF document
PdfDocument destDoc = new PdfDocument();
// Source PDF documents
string[] source = { "Src1.pdf", "Src2.pdf" };
PdfMergeOptions option = new PdfMergeOptions();
option.OptimizeResources = true;
//Merge the source pdf document.
destDoc = PdfDocument.Merge(source, option);
destDoc.Save("Merge.pdf");
' Destination PDF document
Dim destDoc As PdfDocument = New PdfDocument()
' Source PDF documents
Dim source() As String = { "Src1.pdf", "Src2.pdf" }
'Merge the source pdf document.
Dim [option] As PdfMergeOptions = New PdfMergeOptions()
[option].OptimizeResources = True
destDoc = PdfDocument.Merge(source, [option])
destDoc.Save("Merge.pdf")
See Also
Save(Stream)
Saves the document to the specified output stream.
Declaration
public abstract void Save(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The stream object where PDF document will be saved. |
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg, 20, 20, 100, 200);
// Save the document as a stream
MemoryStream stream = new MemoryStream();
doc.Save(stream);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg, 20, 20, 100, 200)
' Save the document as a stream
Dim stream As MemoryStream = New MemoryStream()
doc.Save(stream)
See Also
Save(Stream, HttpContext)
Saves the document into a HTTP response stream.
Declaration
public void Save(Stream stream, HttpContext response)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | The stream where to save the PDF document. |
System.Web.HttpContext | response | The HTTP response stream object. |
Remarks
This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
MemoryStream stream = new MemoryStream();
// Save the document as a stream
doc.Save(stream, Response);
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
Dim stream As MemoryStream = New MemoryStream()
' Save the document as a stream
doc.Save(stream, Response)
'Close the document
doc.Close(True)
See Also
Save(String)
Saves the document to the specified filename.
Declaration
public void Save(string filename)
Parameters
Type | Name | Description |
---|---|---|
System.String | filename | The name of the file where to save the document. It can be a full path or a relative path. |
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
doc.Save("SaveExample.pdf");
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
'Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
doc.Save("SaveExample.pdf")
Save(String, HttpResponse, HttpReadType)
Saves the document into a HTTP response stream.
Declaration
public void Save(string fileName, HttpResponse response, HttpReadType type)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | The name of the document. |
System.Web.HttpResponse | response | The HTTP response stream object. |
HttpReadType | type | The type of the reading document. |
Remarks
If a document containing digital signature needs to be saved then the destination stream must support seeking, otherwise an exception will be raised. Since the HTTP response stream does not support seeking please write the document to a memory stream first and then flush it to the destination stream to avoid raising an exception. This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight
Examples
//Create a new document.
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Loads an Image
PdfImage pdfImg = new PdfBitmap(Image.FromFile("Logo.png"));
//Draw the image
g.DrawImage(pdfImg,20, 20, 100,200);
doc.Save("SaveExample.pdf", Response, HttpReadType.Open);
//Close the document
doc.Close(true);
'Create a new document.
Dim doc As PdfDocument = New PdfDocument()
'Create a page
Dim page As PdfPage = doc.Pages.Add()
Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics
' Loads an Image
Dim pdfImg As PdfImage = New PdfBitmap(Image.FromFile("Logo.png"))
'Draw the image
g.DrawImage(pdfImg,20, 20, 100,200)
doc.Save("SaveExample.pdf", Response, HttpReadType.Open)
'Close the document
doc.Close(True)
See Also
StyleToString(PdfCheckBoxStyle)
Declaration
protected string StyleToString(PdfCheckBoxStyle style)
Parameters
Type | Name | Description |
---|---|---|
PdfCheckBoxStyle | style |
Returns
Type |
---|
System.String |
Events
SaveProgress
Occurs when the document is being saved.
Declaration
public event PdfDocumentBase.ProgressEventHandler SaveProgress
Event Type
Type |
---|
PdfDocumentBase.ProgressEventHandler |
Remarks
This event raised on saving the document. It will keep track of the save progress of the document.
Examples
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add new pages to the document.
PdfPage page = document.Pages.Add();
//Create font and font style.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
//Draw text in the new page.
page.Graphics.DrawString("Essential PDF", font, PdfBrushes.Black, new PointF(10, 10));
document.SaveProgress += new PdfDocument.ProgressEventHandler(document_SaveProgress);
//Saves the document
document.Save("Document.pdf");
//Close the document
document.Close(true);
// Event handler for PageAdded event
void document_SaveProgress(object sender, ProgressEventArgs arguments)
{
MessageBox.Show(String.Format("Current: {0}, Progress: {1}, Total {2}", arguments.Current, arguments.Progress, arguments.Total));
}
'Create a new PDF document.
Private document As PdfDocument = New PdfDocument()
'Add new pages to the document.
Private page As PdfPage = document.Pages.Add()
'Create font and font style.
Private font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold)
'Draw text in the new page.
page.Graphics.DrawString("Essential PDF", font, PdfBrushes.Black, New PointF(10, 10))
AddHandler document.SaveProgress, AddressOf document_SaveProgress
'Saves the document
document.Save("Document.pdf")
'Close the document
document.Close(True)
' Event handler for PageAdded event
Private Sub document_SaveProgress(ByVal sender As Object, ByVal arguments As ProgressEventArgs)
MessageBox.Show(String.Format("Current: {0}, Progress: {1}, Total {2}", arguments.Current, arguments.Progress, arguments.Total))
End Sub