PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 4:20 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Oct 13, 2023 2:47 pm 
Offline

Joined: Fri Oct 13, 2023 2:44 pm
Posts: 1
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.

Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 15, 2023 8:26 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 340
Not repro.
There is no "GetText" in our version of PdfPage.
Which library are you using?

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 394 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group