Complete .NET examples for common PDF to Text tasks. See the .NET SDK guide for installation and result handling.
You can run the examples below with the displayed API credentials. Update the input URLs and filenames as needed. Each .NET example can be copied and run independently.
Choose file, in-memory, or output-stream handling for the text result. Stream examples use a binary file stream as their destination.
The memory variants return UTF-8 bytes. Decode them when your application needs a text string.
Upload an existing invoice.pdf file.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.convertFileToFile("invoice.pdf", "invoice.txt"); } }
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); byte[] text_bytes = client.convertFile("invoice.pdf"); Console.WriteLine(text_bytes.Length); } }
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); using (Stream output_stream = File.Create("invoice.txt")) { client.convertFileToStream("invoice.pdf", output_stream); } } }
Fetch a PDF from its URL.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.convertUrlToFile( "https://your-server.com/invoice.pdf", "invoice.txt" ); } }
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); byte[] text_bytes = client.convertUrl( "https://your-server.com/invoice.pdf" ); Console.WriteLine(text_bytes.Length); } }
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); using (Stream output_stream = File.Create("invoice.txt")) { client.convertUrlToStream( "https://your-server.com/invoice.pdf", output_stream ); } } }
Read invoice.pdf as binary data. In an application, pass the bytes you already hold in memory instead.
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); byte[] pdf_data_1 = File.ReadAllBytes("invoice.pdf"); client.convertRawDataToFile(pdf_data_1, "invoice.txt"); } }
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); byte[] pdf_data_1 = File.ReadAllBytes("invoice.pdf"); byte[] text_bytes = client.convertRawData(pdf_data_1); Console.WriteLine(text_bytes.Length); } }
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); using (Stream output_stream = File.Create("invoice.txt")) { byte[] pdf_data_1 = File.ReadAllBytes("invoice.pdf"); client.convertRawDataToStream(pdf_data_1, output_stream); } } }
Open invoice.pdf as a binary input stream and save the result to invoice.txt.
using System; using System.IO; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); using (Stream input_stream = File.OpenRead("invoice.pdf")) { client.convertStreamToFile(input_stream, "invoice.txt"); } } }
Convert a PDF URL, decode the returned bytes as UTF-8, and print the resulting string.
using System; using System.Text; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); byte[] text_bytes = client.convertUrl("https://your-server.com/invoice.pdf"); string text = Encoding.UTF8.GetString(text_bytes); Console.WriteLine(text); } }
These examples upload extraction.pdf, a three-page document with a two-column article, wrapped paragraphs, and invoice fields.
Extract pages 1 and 3 of extraction.pdf into excerpt.txt.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setPrintPageRange("1,3"); client.convertFileToFile("extraction.pdf", "excerpt.txt"); } }
Extract the article on page 1 into article.txt without spacing that recreates the PDF's columns. For tables, the default layout mode usually preserves column alignment better.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setNoLayout(true); client.setPrintPageRange("1"); client.convertFileToFile("extraction.pdf", "article.txt"); } }
Extract page 2 into paragraphs.txt, joining wrapped lines with paragraph detection and removing line-end hyphens. For example, infor- followed by mation becomes information. Paragraph detection depends on the document's layout.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setParagraphMode("bounding-box"); client.setPrintPageRange("2"); client.setRemoveHyphenation(true); client.convertFileToFile("extraction.pdf", "paragraphs.txt"); } }
Crop away the headers and footers on every page, or extract only the customer, invoice, and reference fields on page 3.
The coordinates below match a 612 × 792 point (US Letter) page. Measure X and Y from the top-left corner; 72 points equal one inch. Adjust the regions for your PDF.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setCropAreaHeight(648); client.setCropAreaWidth(540); client.setCropAreaX(36); client.setCropAreaY(72); client.convertFileToFile("extraction.pdf", "body.txt"); } }
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setCropAreaHeight(70); client.setCropAreaWidth(300); client.setCropAreaX(36); client.setCropAreaY(290); client.setPrintPageRange("3"); client.convertFileToFile("extraction.pdf", "fields.txt"); } }
The default output has no page separators. Insert form-feed characters (\f) for processing text by page, or add a visible --- PAGE BREAK --- marker on its own line.
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setPageBreakMode("default"); client.convertFileToFile("extraction.pdf", "pages.txt"); } }
using System; class Example { static void Main() { var client = new pdfcrowd.PdfToTextClient("demo", "demo"); client.setCustomPageBreak(@" --- PAGE BREAK --- "); client.setPageBreakMode("custom"); client.convertFileToFile("extraction.pdf", "separated.txt"); } }