Giter Club home page Giter Club logo

Comments (5)

stephanITC avatar stephanITC commented on June 18, 2024 1

Finally found the issue: the .../vendor/dompdf/dompdf/lib/fonts/ directory has not had sufficient rights to create the .ufm font and .ufm.json file. chmod -R 777 fonts/ made it work.
unfortunately no error reported that...

from dompdf.

bsweeney avatar bsweeney commented on June 18, 2024

Which version of Dompdf are you using? Do you have a sample of the HTML + CSS you're using with that font?

As for the amount of memory, that's only 16MB. Dompdf is not optimized for operation in low-memory environments, so hopefully that is not the maximum amount of memory available to PHP.

from dompdf.

stephanITC avatar stephanITC commented on June 18, 2024

I am using Dompdf 2.0.4.

My Code looks like this:

$dompdf = new Dompdf([
	'isRemoteEnabled' => true,
	'isHtml5ParserEnabled' => true,
	'chroot' => ABSPATH, // this is my constant for the projects absolute path (works for all images, etc)
	'defaultFont' => 'Courier',
]);

$html = '	<!DOCTYPE html>
		<html lang="de">
			<head>
			        <style>
				        @font-face {
					        font-family: "segoe-ui";
					        font-weight: 300;
					        font-style: normal;
					        font-variant: normal;
					        src: url("../public/assets/fonts/segoe-ui/SegoeUI.ttf") format("truetype");
				        }
				        body {
					        font-family: "segoe-ui", sans-serif;
					        font-weight:300;
				        }
			        </style>
			        <title>PDF</title>
        		</head>
				<body>
					This is a string as the only content in the pdf
				</body>
			</html>';

$dompdf->loadHtml( $html );
$dompdf->setPaper('A4');
$dompdf->render();

$canvas = $dompdf->getCanvas();
$canvas->page_script(function ($pageNumber, $pageCount, $canvas, $fontMetrics) use ($dompdf) {
	$text = 'Seite ' . $pageNumber . ' / ' . $pageCount;
	$font = $fontMetrics->getFont('DejaVuSans');
	$size = 9;
	$canvas->text(62, 78, $text, $font, $size);
});

$filename = 'test.pdf';
$dompdf->stream( $filename, [
	'compress' => true,
	'Attachment' => false,
]);

I increased the Memory Limit to 128M. Using the code above i still get:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 65015808 bytes)
Setting up code above with default font "Courier" everything renders as it should.

Additional information:
I am running my Dev-Environment in WSL ( Apache, PHP, MySQL). I gave 32GB of available Memory to WSL via .wslconfig. When opening up my Task Manager and unlimiting the PHP memory_limit i can see my PCs usage increasing from (default) 20GB to up to 30GB before the script breaks.

from dompdf.

bsweeney avatar bsweeney commented on June 18, 2024

I certainly would not expect that particular sample to cause a memory limit exception. Maybe something about your copy of the font is problematic? Have you tried installing another font?

from dompdf.

bsweeney avatar bsweeney commented on June 18, 2024

Dompdf might be swallowing that error to prevent it from halting rendering. Enabling additional debug messaging would have exposed the problem.

I am surprised lack of permissions was causing a memory limit exception. I'd have to look into it to see what Dompdf is doing in that scenario.

FYI there is a request to add a post-installation task to check permissions. I'm also thinking of a way of generating info on demand to validate the installation.

from dompdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.