Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. aspose-cloud-kb created this gist Aug 11, 2024.
    41 changes: 41 additions & 0 deletions Count Words in PDF Document with C# REST API.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    using System;
    using System.IO;
    using Aspose.Pdf.Cloud.Sdk.Api;
    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace Aspose.PDF.Cloud.Examples.Kb
    {
    public class PdfTasks
    {
    public static void CountWords()
    {
    PdfApi pdfApi = new PdfApi("Client Secret", "Client ID");

    String fileName = "sample.pdf";
    String storage = "";
    String folder = "";

    try
    {
    // Upload source file to aspose cloud storage for counting words
    pdfApi.UploadFile(fileName, new MemoryStream(System.IO.File.ReadAllBytes(fileName)));

    // Invoke Aspose.PDF Cloud SDK API to get words count per page from pdf document
    WordCountResponse apiResponse = pdfApi.GetWordsPerPage(fileName, storage, folder);

    if (apiResponse != null && apiResponse.Status.Equals("OK"))
    {
    foreach (PageWordCount PageWordCount in apiResponse.WordsPerPage.List)
    {
    Console.WriteLine("Page Number :: " + PageWordCount.PageNumber + " Total Words :: " + PageWordCount.Count);
    }
    Console.ReadKey();
    }
    }
    catch (Exception ex)
    {
    System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
    }
    }
    }
    }