Created
August 11, 2024 16:35
-
-
Save aspose-cloud-kb/dfded4473660d220829162064f9ef8c7 to your computer and use it in GitHub Desktop.
Count Words in PDF Document with C# REST API. https://kb.aspose.cloud/pdf/net/count-words-in-pdf-document-with-net-rest-api/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment