using PdfSharp.Pdf; using PdfSharp.Pdf.IO; using System.IO; class PdfToCsvConverter { public void Convert(string pdfFilePath, string csvFilePath) { // Create a new PDF document object PdfDocument pdfDoc = PdfReader.Open(pdfFilePath, PdfDocumentOpenMode.Import); // Create a new stream writer to write the CSV file using (StreamWriter writer = new StreamWriter(csvFilePath)) { // Loop through each page in the PDF document foreach (PdfPage page in pdfDoc.Pages) { // Extract the text from the current page string text = page.GetText(); // Split the text into lines string[] lines = text.Split('\n'); // Loop through each line and write it to the CSV file foreach (string line in lines) { // Split the line into fields using a comma delimiter string[] fields = line.Split(','); // Write the fields to the CSV file writer.WriteLine(string.Join(",", fields)); } } } } }
I am using this code to covert the follow document into text. Yet the result is mess. I've attached a test pdf to try with. Please help.
Last edited by Yordan1 on Thu Oct 19, 2023 6:22 pm, edited 1 time in total.
|