Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OverWrite(): does not handle CRLF documents correctly #626

Open
Magnanimity opened this issue Jan 31, 2018 · 15 comments

Comments

Projects
None yet
10 participants
@Magnanimity
Copy link

commented Jan 31, 2018

I found this bug / would like to have this new functionality

Undefined Offset: 1 - mPDF.php Line 29198

29196:        $xref = [];
29197:        preg_match("/xref\n0 (\d+)\n(.*?)\ntrailer/s", $pdf, $m);
29198:        $xref_objid = $m[1];
29199:        preg_match_all('/(\d{10}) (\d{5}) (f|n)/', $m[2], $x);
29200:        for ($i = 0; $i < count($x[0]); $i++) {
29201:            $xref[] = [intval($x[1][$i]), $x[2][$i], $x[3][$i]];

This is mPDF and PHP version and environment (fpm/cli etc) I am using

mPDF 7.0.0
PHP 5.6.31 (also tried PHP 7.0.23 & PHP 7.1.9)
Apache 2.4.27
Symfony 3.2.13
(WAMPSERVER 3.1.0 - 64-bit)

This is a PHP code snippet I use

    /**
     * @Route("/test/", name="test")
     */
    public function testAction(Request $request)
    {
        $mpdf = new \Mpdf\Mpdf();
	$mpdf->SetImportUse();

	$mpdf->percentSubset = 0;

	$search = array(
		'{{test1}}',
		'{{test2}}'
	);

	$replacement = array(
		"THIS IS A TEST",
		"THIS IS ANOTHER TEST"
	);

	if (!file_exists('../test.pdf')) die("FILE DOES NOT EXIST");
		
	$mpdf->OverWrite('../test.pdf', $search, $replacement, 'D', 'report.pdf' ) ;
     }

screencapture_563
screencapture_564

@Magnanimity

This comment has been minimized.

Copy link
Author

commented Feb 8, 2018

Hi,

Is there perhaps any ETA on resolving this?

Thanks

@Klap-in

This comment has been minimized.

Copy link
Contributor

commented Feb 8, 2018

Nope.

Could you provide an example of test.pdf as well?

@Magnanimity

This comment has been minimized.

Copy link
Author

commented Feb 8, 2018

Example Attached.

The PDF was generated with Windows "Print to PDF" and then the {{test}} parameters were inserted using NitroPDF.

test.pdf

@Cosmologist

This comment has been minimized.

Copy link

commented Mar 16, 2018

The same problem

@OctaneInteractive

This comment has been minimized.

Copy link

commented Apr 30, 2018

Yeah, also having the same problem.

@finwe

This comment has been minimized.

Copy link
Member

commented Apr 30, 2018

It seems OverWrite has a problem with PDF files using CRLF line endings. I tried to edit failing regexes but to no avail (resulting files were empty). Leaving open.

@finwe finwe added the help wanted label Apr 30, 2018

@finwe finwe changed the title mpdf->OverWrite(): Undefined offset: 1 OverWrite(): does not handle CRLF documents correctly Apr 30, 2018

@h2ooooooo

This comment has been minimized.

Copy link

commented Aug 16, 2018

I couldn't figure out how to save a PDF in Word 2016 (office 365) that didn't end up with CRLF rather than LF in newline, and I assume that the startxref references would fail if you simply replaced all CRLF with LF. I tried using PDF printers (two, both Chrome and Microsofts) as well as having Google Drive convert it for me, and nothing helped.

Finally I went ahead and converted it with unoconv and it replaced the CRLF's with LF characters instead and allows me to use mpdf to replace.

@danieljausovec

This comment has been minimized.

Copy link

commented Oct 12, 2018

Is there already a solution for this?

@finwe

This comment has been minimized.

Copy link
Member

commented Oct 12, 2018

If it were, the issue would be closed.

@studioramix

This comment has been minimized.

Copy link

commented Feb 19, 2019

Is this going to be resolved?

@finwe

This comment has been minimized.

Copy link
Member

commented Feb 19, 2019

image

jokes aside: only if someone puts time into it which doesn't seem likely ATM.

@studioramix

This comment has been minimized.

Copy link

commented Feb 19, 2019

any temporary workaround or successful tool that can fix the original PDF to work with this function?

the "dirty" way for me around this for now is with manually placing text based on position, but no need to explain why this is really dirty ;)

$mpdf->SetTextColor(222,0,0);
$mpdf->SetXY(55,0);
$mpdf->WriteCell(22,44,"Bananna");
@h2ooooooo

This comment has been minimized.

Copy link

commented Feb 19, 2019

@studioramix As I mentioned in my post I successfully used unoconv to convert it to a working format (LF instead of CRLF). Obviously it requires you to run through this either manually or automatically through your code.

@Sivustonikkari

This comment has been minimized.

Copy link

commented Mar 7, 2019

I tried creating a pdf with Adobe Acrobat with the Create->pdf from clipboard -option. On the clipboard I had two lines of text copied from Notepad++ with EOL characters converted to LF only. Even that did not work. Is there a working example of a pdf file that can be used for testing?

@ekaprasasti

This comment has been minimized.

Copy link

commented May 3, 2019

is problem solve here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.