Xceed PDF Library for .NET Documentation v1.0
In This Topic
    Get information about a document
    In This Topic

    Introduction

    The following example demonstrates how to get things like the title, author & creation date of a PDF document.


    Get information about a PDF document (C#)
    Copy Code
    public static void GetDocumentInformations()
    {
      Console.WriteLine( "=== GET DOCUMENT INFORMATIONS ===" );
      var filename = "TikainAction.pdf";
    
      // Load a pdf document.
      using( var pdfDoc = PdfDocument.Load( PdfDocumentsSample.PdfDocumentsSampleResourceDirectory + filename ) )
      {
        var outputFileName = "GetDocumentInformations.pdf";
        var outputPath = PdfDocumentsSample.PdfDocumentsSampleOutputDirectory + outputFileName;
    
        // Create a pdf document.
        using( var pdfoutput = PdfDocument.Create( outputPath ) )
        {
          // Get the first page of the document.
          var page = pdfoutput.Pages.First();
    
          // Add title.
          var titleStyle = TextStyle.WithFont( pdfoutput.Fonts.GetStandardFont( StandardFontType.Helvetica ), 15d );
          page.AddParagraph( "Get Document Informations", titleStyle, new ParagraphStyle( ParagraphHorizontalAlignment.Center ) );
    
          var exportData = new ExportInfoToPdf();
    
          // Add Text.
          exportData.AddLine( pdfoutput, $"Printing Document info from: {filename}\n\n", Color.Red );
          exportData.AddLine( pdfoutput, $"Total pages: {pdfDoc.Pages.Count}" );
          exportData.AddLine( pdfoutput, $"PDF Version: {pdfDoc.Version}" );
    
          if( pdfDoc.Informations != null )
          {
            // Add Text for metadata Document Informations.
            exportData.AddLine( pdfoutput, $"Title: {pdfDoc.Informations.Title ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Author: {pdfDoc.Informations.Author ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Subject: {pdfDoc.Informations.Subject ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Creator: {pdfDoc.Informations.Creator ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Producer: {pdfDoc.Informations.Producer ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Creation date: {pdfDoc.Informations.CreationDate?.ToString() ?? "N/A"}" );
            exportData.AddLine( pdfoutput, $"Modification date: {pdfDoc.Informations.ModifiedDate?.ToString() ?? "N/A"}" );
          }
    
          // Save the output document.
          pdfoutput.Save();
          Console.WriteLine( $"Info exported to path: {outputFileName}" );
        }
      }
    }

     Learn More

    To know more about how to get information on a specific page, please consult the "Get Basic Page Information" example.


    See Also