Xamarin.Forms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class PdfDocumentBase

    Show / Hide Table of Contents

    Class PdfDocumentBase

    Represent common properties of PdfDocument and PdfLoadedDocument classes.

    Inheritance
    System.Object
    PdfDocumentBase
    PdfLoadedDocument
    PdfDocument
    Namespace: Syncfusion.Pdf
    Assembly: Syncfusion.Pdf.Portable.dll
    Syntax
    public abstract class PdfDocumentBase : Object
    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 Description
    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
    PdfDocument

    Bookmarks

    Declaration
    public abstract PdfBookmarkBase Bookmarks { get; }
    Property Value
    Type Description
    PdfBookmarkBase

    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 Description
    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
    PdfDocument
    PdfPage

    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 Description
    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
    PdfDocument
    PdfLoadedDocument

    EnableMemoryOptimization

    Gets or sets whether to optimize memory.

    Declaration
    public bool EnableMemoryOptimization { get; set; }
    Property Value
    Type Description
    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 Description
    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
    PdfDocument
    PdfPage

    Layers

    Gets the collection of PdfLayer from the PDF document

    Declaration
    public PdfDocumentLayerCollection Layers { get; }
    Property Value
    Type Description
    PdfDocumentLayerCollection

    PageCount

    Gets the number of pages.

    Declaration
    public abstract int PageCount { get; }
    Property Value
    Type Description
    System.Int32

    PortfolioInformation

    Gets or sets the portfolio information to the Document.

    Declaration
    public PdfPortfolioInformation PortfolioInformation { get; set; }
    Property Value
    Type Description
    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
    PdfDocument

    Security

    Gets the security features of the document like encryption.

    Declaration
    public PdfSecurity Security { get; }
    Property Value
    Type Description
    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
    PdfDocument
    PdfPage

    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 Description
    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
    PdfDocument
    PdfPage

    Methods

    add_SaveProgress(PdfDocumentBase.ProgressEventHandler)

    Declaration
    public void add_SaveProgress(PdfDocumentBase.ProgressEventHandler value)
    Parameters
    Type Name Description
    PdfDocumentBase.ProgressEventHandler value

    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
    PdfDocument
    PdfPage

    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
    PdfDocument
    PdfPage

    Close(Boolean)

    Closes the document.

    Declaration
    public virtual void Close(bool completely)
    Parameters
    Type Name Description
    System.Boolean completely

    if set to true the document should close its stream as well.

    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
    PdfDocument
    PdfPage

    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
    PdfDocument
    PdfPage
    PdfImage

    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
    PdfDocument
    PdfPage

    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
    PdfDocument
    PdfPage

    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
    PdfDocument
    PdfPage

    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
    PdfDocument

    remove_SaveProgress(PdfDocumentBase.ProgressEventHandler)

    Declaration
    public void remove_SaveProgress(PdfDocumentBase.ProgressEventHandler value)
    Parameters
    Type Name Description
    PdfDocumentBase.ProgressEventHandler value

    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
    PdfDocument
    PdfPage

    Events

    SaveProgress

    Occurs when the document is being saved.

    Declaration
    public event PdfDocumentBase.ProgressEventHandler SaveProgress
    Event Type
    Type Description
    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
    See Also
    PdfDocumentBase.ProgressEventHandler

    See Also

    PdfDocument
    PdfLoadedDocument
    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved