Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:50:09+00:00 2026-06-10T17:50:09+00:00

pdfbox issue I used pdfbox to extract text from PDF to my richtextbox. I

  • 0

pdfbox issue

I used pdfbox to extract text from PDF to my richtextbox.

I don’t know what’s the problem but there are PDF that are good but there are PDF that throws an exception, the exception is:

Object reference not set to an instance of an object.

Here’s my code:

using org.pdfbox.pdmodel;
using org.pdfbox.util;

private void pdfButton_Click(object sender, EventArgs e)
{
    OpenFileDialog openFD = new OpenFileDialog();
    openFD.FileName = "";
    openFD.InitialDirectory = "C:\\";
    openFD.Filter = "All PDF Files|*.PDF";
    openFD.Title = "Browse all PDF files";

    if (openFD.ShowDialog() == DialogResult.OK)
    {
        try
        {
            pdf_filename = Path.GetFileNameWithoutExtension(openFD.Filename);
            PDDocument pdfFile = PDDocument.load(openFD.Filename);

            PDFTextStripper pdfStripper = new PDFTextStripper();
            richtextBox1.Text = pdfStripper.getText(pdfFile);
            textBox1.Text = Path.GetFileName(openFD.Filename);
        }
        catch (Exception error)
        {
            MessageBox.Show(error.ToString());
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:50:10+00:00Added an answer on June 10, 2026 at 5:50 pm

    I fixed the issue using iTextSharp. This was advised by my co-worker, I changed the PDFBox by iTextSharp.

    If someone will have the same issue as me here’s the working code:

    using iTextSharp.text.pdf;
    using iTextSharp.text.pdf.parser;
    
    
    private void pdfButton_Click(object sender, EventArgs e)
    {
        OpenFileDialog openFD = new OpenFileDialog();
        openFD.FileName = "";
        openFD.InitialDirectory = "C:\\";
        openFD.Filter = "All PDF Files|*.PDF";
        openFD.Title = "Browse all PDF files";
    
        if (openFD.ShowDialog() == DialogResult.OK)
        {
            try
            {
                pdf_filename = Path.GetFileNameWithoutExtension(openFD.Filename);
    
                richtextBox1.Text = ReadPdf(openFD.FileName);
                textBox1.Text = Path.GetFileName(openFD.Filename);
            }
    
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
    
        }
    }
    
    
    private string ReadPdf(string filename)
    {
    
        if (!File.Exists(filename)) return string.Empty;
    
        PdfReader reader = new PdfReader(filename);
    
        string text = string.Empty;
    
        for (int page = 1; page <= reader.NumberOfPages; page++)
        {
    
            text += PdfTextExtractor.GetTextFromPage(reader, page);
    
        }
    
        return text;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using pdfbox library to extract text contents from pdf file.I would able
I'm using Apache PDFBox to extract text from several PDF files. The files are
I'm using PDFBox to extract the outline (bookmarks) information from PDF files, that's even
I've heard about the PDFBox , but is there another good tool for converting
When I try to extract text from my PDF files, it seems to insert
I'm writing a java app that creates a pdf from scratch using the pdfbox
I am new to pdfbox and I want to extract a paragraph that matches
There were questions on that but not recently and technology must have gone ahead
I'm using PDFBox and iText to create a simple (just paragraphs) pdf document from
I've being researching on how to extract images from a big (> 300MB) PDF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.