Parsing with unknown text. Help me resolve
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 7.4
- PDFParser Version: 2.9.0
Description:
PDF input
Cannot provide pdf since its confidential
Expected output & actual output
Need to extract table from it
Code
$parser = new \Smalot\PdfParser\Parser();
// Source PDF file to extract text
$file = "tables 2024.pdf";
// Parse pdf file using Parser library
//$pdf = $parser->parseFile($file);
$pdf = $parser->parseContent(file_get_contents($file));
// Extract text from PDF
//$text = $pdf->getText();
$text = $pdf->getPages()[2]->getText();
// Add line break
$pdfText = nl2br($text);
/$ascii_decoded = mb_convert_encoding($pdfText, 'UTF-8', 'ASCII');
$ansi_decoded = mb_convert_encoding($ascii_decoded, 'UTF-8', 'ISO-8859-1');
$decode1252 = mb_convert_encoding($ansi_decoded, 'UTF-8', 'Windows-1252');
$utf8_decode = utf8_decode($decode1252);/
$encodings = ['UTF-8', 'ISO-8859-1', 'Windows-1252', 'Windows-1251', 'ISO-8859-15'];
$decodedText = $pdfText;
foreach ($encodings as $encoding) {
$decodedText = mb_convert_encoding($decodedText, 'UTF-8', $encoding);
if ($decodedText) {
// If decoding is successful, break the loop
//break;
}
}
$utf8_decode = utf8_decode($decodedText);
print_r($utf8_decode);
The output.. not working
ZZZFDOFKRLFHFRP
5HJXODWRU\B6WDWXVBB
%HQHILWV3ODQVQRWHGDV³3HQGLQJ$SSURYDO´KDYHEHHQILOHGZLWKWKH&DOLIRUQLDUHJXODWLQJVWDWHDJHQFLHVDQGDUHSHQGLQJ
DSSURYDOZLWKWKRVHVWDWHDJHQFLHV
PLATINUM TIER
%HQHILW3ODQ+HDOWK3ODQ1HWZRUN1DPH 5HJXODWRU\6WDWXV
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by reproducing the reported parseContent(file_get_contents($file)) and getPages()[2]->getText() flow with a non-confidential PDF that shows the same output, then inspect how extracted character encodings are handled. Done means the affected text is extracted legibly without relying on the reporter's post-processing conversions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100