'How do raw PDF data and convert it into another PDF file using a bash script?

I am trying to convert raw PDF data into a PDF file to run pdftotext on. The data from file1.pdf is the data I want. If I call the following:

cat file1.pdf > file2.pdf

pdftotext works fine on file2.pdf.

However, if I try to run the following:

VAR1=$(cat file1.pdf)
echo $VAR1 > file2.pdf
pdftotext file2.pdf -

I end up with the following errors:

Syntax Error (99): Illegal character ')'
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table

Is there anyway I can use the latter structure? I need to do it this way since the bash script will accept the contents of a PDF file and not the PDF file itself.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source