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";
    
      // Loads a PdfDocument.
      using( var pdfDoc = PdfDocument.Load( PdfDocumentsSample.PdfDocumentsSampleResourceDirectory + filename ) )
      {
        var outputFileName = "GetDocumentInformations.pdf";
        var outputPath = PdfDocumentsSample.PdfDocumentsSampleOutputDirectory + outputFileName;
    
        // Creates a PdfDocument.
        using( var pdfoutput = PdfDocument.Create( outputPath ) )
        {
          // Gets the first Page of the document.
          var page = pdfoutput.Pages.First();
    
          // Adds a title.
          var titleStyle = TextStyle.WithFont( pdfoutput.Fonts.GetStandardFont( StandardFontType.Helvetica ), 15d );
          page.AddParagraph( "Get Document Informations", titleStyle, new ParagraphStyle( ParagraphHorizontalAlignment.Center ) );
    
          // Adds red Courier text at a specific Y position.
          var redTextStyle = TextStyle.WithFontAndColor( pdfoutput.Fonts.GetStandardFont( StandardFontType.Courier ), 12d, Brushes.Red );
          page.AddParagraph( $"Printing Document info from: {filename}", 40, redTextStyle );
    
          // Adds Courier Text at a specific Y position.
          var textStyle = TextStyle.WithFont( pdfoutput.Fonts.GetStandardFont( StandardFontType.Courier ), 12d );
          page.AddParagraph( $"PDF Version: {pdfDoc.Version}", 90, textStyle );
          page.AddParagraph( $"Total pages: {pdfDoc.Pages.Count}", 105, textStyle );
    
          if( pdfDoc.Informations != null )
          {
            // Adds text with the metadata DocumentInformations.
            page.AddParagraph( $"Title: {pdfDoc.Informations.Title ?? "N/A"}", 120, textStyle );
            page.AddParagraph( $"Author: {pdfDoc.Informations.Author ?? "N/A"}", 135, textStyle );
            page.AddParagraph( $"Subject: {pdfDoc.Informations.Subject ?? "N/A"}", 150, textStyle );
            page.AddParagraph( $"Creator: {pdfDoc.Informations.Creator ?? "N/A"}", 165, textStyle );
            page.AddParagraph( $"Producer: {pdfDoc.Informations.Producer ?? "N/A"}", 180, textStyle );
            page.AddParagraph( $"Creation date: {pdfDoc.Informations.CreationDate?.ToString( CultureInfo.InvariantCulture ) ?? "N/A"}", 195, textStyle );
            page.AddParagraph( $"Modification date: {pdfDoc.Informations.ModifiedDate?.ToString( CultureInfo.InvariantCulture ) ?? "N/A"}", 210, textStyle );
          }
    
          // Saves 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

    Add elements in a PDF document