Linux convert pdf to text

Convert PDF to Text on Linux

PDFelement New Year Sale

A convert PDF to text job on Linux is easy if you know a few tips and tricks in your particular distro, but what if you’re new to Linux and you need to get a PDF document converted to a text-based equivalent? Are there any Linux tools specifically designed for this? How about OCR modules — how do you get them for Linux? The answers to these questions all in this article, so read on to learn more about how to convert PDF to text in Linux.

2 Methods to Convert PDF to Text on Linux

Let’s look at a couple of ways to do this on a Linux desktop and the tools for those.

Method 1: Use an eBook Application

Essentially, what you want to do is convert a non-editable and possibly non-searchable PDF document and convert the content without actually changing the format. For this, you can use freeware or an open-source application like Calibre. It is available in most repos for Ubuntu, Mint, Fedora, and other popular distros. The correct syntax varies from one distribution to another, but your basic Terminal command should look something like this:

sudo apt install calibre

Once installed, you can follow the flow of the process from within the application. Here’s what it should look like:

  • 1. Launch the application and click the Add Books button on the top left to import one or more scanned or non-editable PDF documents.
  • 2. When you see the PDFs in the list below the Calibre toolbar, select the file(s) you want to convert to text and hit the Convert Books option at the top.
  • 3. Choose the format of the output file to TXT in the conversion window and hit OK to convert.

pdf to text linux

You can now open the file in any text editor and make changes or edit the content the way you want. This does not retain the format of the original but it’s a fairly authentic copy of the non-editable file. The original PDF document will be unchanged, so you can save the new version with a slightly different name like Doc1_OCR, Doc2_OCR, and so on.

Method 2: Use Terminal Commands

On the other hand, if you’re at an expert level on your Linux machine, you can try the command line way of converting PDF to text. For this, you can use something like pdftotext. It’s part of the Poppler package but the name might vary based on which distro you’re using. The first step is to install it, and you can do it with the following commands:

Читайте также:  Анализ wifi сетей linux

1. First, type the following in Terminal and hit «Enter»

sudo apt install poppler-utils [Works for Debian, Mint, Ubuntu, etc.]

2. The next command is the one for conversion, and it should look like this:

pdftotext -layout source.pdf target.txt [Source is the original PDF and Target is the final output]

To execute the above command, the Terminal prompt needs to be in the same folder location as your source PDF file. Alternatively, you can define a file path before the source and target file names within the command.

3. Hit Enter to run the command on the entire PDF document. To convert just a single range of pages within the document, modify the syntax to match the one shown below:

pdftotext -layout -f M -l N source.pdf target.txt [where M is the first page and N is the last one to be converted.]

linux pdf to text

How to Convert PDF to Text on Windows and Mac

Now you know how to convert PDF to text in Linux, how about Windows or Mac? Do you know how to do the same thing on these OS platforms? If not, read on to learn about a unique and robust utility to do the same job in operating systems other than Linux.

Wondershare PDFelement — PDF Editor is a cross-platform PDF editor with desktop and mobile applications for PDF management. They’re a lightweight family of PDF tools that are incredibly powerful and versatile. More importantly, they’re far more affordable than some of the other premium options that rule the market today. For that reason, PDFelement is quickly becoming the de facto PDF editor for businesses that can’t afford expensive alternatives. In addition, it boasts these features:

linux pdf to txt

  • Full editing capability for all PDF text, images, links, media, and other objects.
  • Comprehensive markup tools to annotate PDFs.
  • Strong security features for redaction, watermarking, encryption, and digital signing.
  • Advanced batch processes for conversion and OCR tasks.
  • Fully-integrated forms management: create interactive forms, convert from non-editable PDF forms, access a large template library, extract data from forms and PDFs in bulk, etc.
  • Robust ‘to and from PDF’ conversion capability with very wide file-type support.
  • More accurate and faster than many premium PDF editors.

Steps for Converting PDF to Text in Windows and Mac:

  • 1. After launching PDFelement on your Windows PC, import the file by dragging it into the software window or just click on «File» → «Open» and get it that way. Even when the PDF editor is closed, you can open a document by dragging its icon over the app’s icon.
  • 2. If you click on the «Convert» tab option at the top, you’ll see a button in the toolbar right below it with the words «To Text» and an icon. The mouseover (tooltip) should say «Convert your PDF to text». Click on the button.
  • 3. Specify your output folder and, if you need to, you can change the output file type on the «Save As» dialog box, too.
Читайте также:  What is system calls in linux

pdftotext ubuntu

Mac (macOS versions including 10.15 Catalina):

PDFelement is equally intuitive on a Mac as it is in Windows. You might see a lot of UI differences between the two, but those features have been designed to work as closely as possible with the nuances of their platforms. The end result is a pretty native experience on any platform, including touchscreen-based iOS and Android devices and screens.

  • 1. PDFelement for Mac has a distinctively Mac App feel to it as soon as you install and launch the application. You can open your PDF using the same methods as for Windows — drag-and-drop or using the «File» menu.
  • 2. Again, in the «File» menu, you’ll see an option called «Export To», which opens another contextual menu. Select «Text» as your option and wait for the conversion to be completed.

linux convert pdf to text

Now you know all there is to know about how to convert PDF to Text on Linux, Windows, and Mac.

Источник

Pdftotext, convert a PDF to text from the terminal

about pdftotext

In the next article we are going to take a look at pdftotext. This is an open source command line utility that will allow us to convert PDF files to plain text files. Basically what it does is extract the text data from the PDF files. This software is free and is included by default in many Gnu / Linux distributions.

In the following lines we are going to see a tool for the terminal, but for the same purpose of extracting text from PDF files you can also use a graphical tool like Caliber. It is worth noting that both the graphical tool and the one that we can use in the terminal, they cannot extract the text if the PDF is made of images (photographs, scanned book images, etc.).

On most Gnu / Linux distributions, pdftotext is included as part of the poppler-utils package. This tool is a command line utility that convert PDF files to plain text. In it we will find many options available, including the ability to specify the range of pages to convert, the ability to keep the original physical layout of the text as well as possible, set line endings, and even work with password-protected PDF files.

about remove a known password from a pdf

Install pdftotext on Ubuntu

To install this tool on our Ubuntu system, in case you don’t already have it installed, you just have to open a terminal (Ctrl + Alt + T) and write the following command in it to install poppler-utils:

install poppler utils

sudo apt install poppler-utils

How to use pdftotext

Convert a PDF file to text

Once we have the package installed on our operating system, we can convert a PDF file to plain text. Can try to keep the original design using the option -layout with the command, but we can also try without it. In a terminal (Ctrl + Alt + T) the command to use would be the following:

Читайте также:  Canon mf410 driver linux

pdftotext convert pdf to plain text

pdftotext -layout pdf-entrada.pdf pdf-salida.txt

In the previous command we would have to replace pdf-input.pdf with the name of the PDF file that we are interested in converting, and pdf-output.txt by the name of the TXT file in which we want to save the text of the input PDF file. If we don’t specify any output text file, pdftotext will automatically name the file with the same name as the original PDF file but with a txt extension. Another thing that can be interesting to add to the command will be the paths before the file names if necessary (~ / Documents / pdf-input.pdf).

Convert only a range of PDF pages to text

If we are not interested in converting the entire PDF file, and we want narrow down a range of PDF pages to convert to text there will be use -f option (first page to convert) Y -l (last page to convert) followed by each option with the page number. The command to use would be something like the following:

pdftotext -layout -f P -l U pdf-entrada.pdf

save in text format a given number of pages of a pdf

In the previous command you will have to replace the letters P and U with the first and last page numbers to extract. The name of pdf-input.pdf We will also have to change it and give it the name of the PDF file with which we want to work.

Use end-of-line characters

This we will be able to specify using -eol followed by mac, dos or unix. The following command will add unix line endings:

pdftotext -layout -eol unix pdf-entrada.pdf

Help

To withdraw from your check available options, run the man page:

man pdftotext

It also can consult the help option with the command:

help command pdftotext

Convert PDF files from a folder using a Bash FOR loop

In case we want to convert all PDF files in a folder to text files, pdftotext does not support batch conversion from PDF to text. Esto we will be able to do it using a Bash FOR loop in terminal (Ctrl + Alt + T):

for file in *.pdf; do pdftotext -layout "$file"; done

To withdraw from your more information about pdftotext, you can consult the project website. In case you prefer not to have to type commands in the terminal, you can also use a online service to get the same result.

The content of the article adheres to our principles of editorial ethics. To report an error click here.

Full path to article: ubunlog » Ubuntu » Pdftotext, convert a PDF to text from the terminal

A comment, leave yours

Leave a Comment Cancel reply

Moypher Nightkrelin said

yes, well it works, but sometimes I have to do OCR or use Libre Office Draw. In addition there are many pdf editors. and apparently this does not happen to text the images, so I do not see it practical. And Libre Office Draw is intuitive and practical.

Источник

Оцените статью
Adblock
detector