1

I'm looking to parse some PDF (extract paragraph from them). I used iTextSharp in the past, but it doesn't support .NET Core.

I also tried this lib: https://github.com/VahidN/iTextSharp.LGPLv2.Core but the text extraction doesn't work very nicely. It just writes random words, not in the correct order, with a lot of incorrect symbols, really not usable.

1
  • PDF parsing is incredibly difficult, because of (some of the many) ways a PDF can encode text. Like not actually encoding the space character, and just having each word (or character) be positioned. I would suggest that PDF parsing is AI-complete (en.wikipedia.org/wiki/AI-complete) Commented Oct 17, 2017 at 8:31

3 Answers 3

0

Essential PDF can be used to load PDFs and extract content from them..NET Core is also supported.

//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
//Load the first page.
PdfPageBase page = loadedDocument.Pages[0];
//Extract text from first page.
string extractedText = page.ExtractText();
//Close the document
loadedDocument.Close(true);

The entire product is available for free with no limitations through the community license if you qualify.

Note: I work for Syncfusion

39
  • I dont earn more than a million, so I should be able to benefit from it. I will test this this evening, thank you
    – J4N
    Commented Apr 20, 2017 at 3:39
  • Can I get it from a Nuget package? If not, what DLL should I include to get this PdfLoadedDocumentDLL?
    – J4N
    Commented Apr 20, 2017 at 4:16
  • @J4N: Yes. Nuget feed for .NET Core. The DLLs needed are Syncfusion.Compression.Portable.dll and Syncfusion.Pdf.Portable.dll Commented Apr 20, 2017 at 12:59
  • It seems that I don't have an ExtractTextmethod on the PdfPageBase? What am I missing?
    – J4N
    Commented Apr 20, 2017 at 14:51
  • 1
    @J4N: Can you please create a support ticket in the Syncfusion support portal and provide a sample PDF document and the text that you are trying to extract. I am working with the developers to get the functionality ported as soon as possible and have additional details will help. Thanks. Commented Apr 26, 2017 at 19:03
0

XFINIUM.PDF library supports text extraction on .NET Core platform.

// Load the PDF document
PdfFixedDocument document = new PdfFixedDocument(input);
// Create a content extractor for the desired page
PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]);
// Extract text as objects with information about position, font, color, etc
PdfTextFragmentCollection tfc = ce.ExtractTextFragments();
// Or extract the text as a simple string.
string text = ce.ExtractText();

Evaluation version is available for download on nuget.org, package id is xfinium.pdf.netcore.

Disclaimer: I work for the company the develops XFINIUM.PDF library.

1
  • Thank you, but it's for a free, very small and open source project, and I cannot afford this kind of fees
    – J4N
    Commented Apr 20, 2017 at 3:36
0

PdfLib CORE is a library for modern .NET Core applications to edit and read PDF files.

Snippet from the readme.md:

var dpiX, dpiY = 300D;
var i = 0;

using var pdfDocument = new PdfDocument(File.Open(<<file>>, FileMode.Open));
foreach (var page in pdfDocument.Pages)
{
    using var pdfPage = page;
    var pageWidth = (int) (dpiX * pdfPage.Size.Width / 72);
    var pageHeight = (int) (dpiY * pdfPage.Size.Height / 72);

    using var bitmap = new PdfiumBitmap(pageWidth, pageHeight, true);
    pdfPage.Render(bitmap, PageOrientations.Normal, RenderingFlags.LcdText);
    using var stream = bitmap.AsBmpStream(dpiX, dpiY);
    
    // <<< do something with your stream...>>> 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.