0

Currently working on validating the pdf file. I have used PHP pdfparser in Laravel to extract the file. But some files are unable to extract. I come up with the solution to downgrade the pdf file to resolve the issue but still not working for me.

I tried to downgrade the pdf file from version 1.7 to 1.4 but it's not allowing me to do so.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Smalot\PdfParser\Parser;
use Xthiago\PDFVersionConverter\Guesser\RegexGuesser;
use Symfony\Component\Filesystem\Filesystem;
use Xthiago\PDFVersionConverter\Converter\GhostscriptConverterCommand;
use Xthiago\PDFVersionConverter\Converter\GhostscriptConverter;

class ApiController extends Controller {

    public function varifyDocument(Request $request, Parser $parser) {
        $request = $request->file();
        $file = $request['file'];

        //Get the version of the pdf file.
        $guesser = new RegexGuesser();
        $version = $guesser->guess($file);

        //If pdf version is 1.7 then convert it to 1.4.
        if($version == "1.7") {
            $command = new GhostscriptConverterCommand();
            $filesystem = new Filesystem();
            $converter = new GhostscriptConverter($command, $filesystem);
            $converter->convert($file, '1.4');
        }

        $pdf = $parser->parseFile($file);
        $pages = $pdf->getPages();
        foreach ($pages as $page) {
            echo $page->getText();
        }
    }
}

I need to read the content of the pdf file and identify it has any vulnerability or not.

Dhaval Mistry
  • 476
  • 1
  • 9
  • 17

0 Answers0