This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Have the set* methods return a Pdfcrowd object

SpartyDan wrote on 2013-11-15:
Could you have the set methods return the Pdfcrowd object?

Currently in PHP you set attributes of the class as follows:

$pdfCrowd = new Pdfcrowd;

$pdfCrowd->setPageWidth('11in');
$pdfCrowd->setPageHeight('8.5in');
$pdfCrowd->setPageMargins('.5in', '.5in', '.5in', '.5in');
$pdfCrowd->usePrintMedia(true);
$pdfCrowd->setInitialPdfZoomType(2);
$pdfCrowd->setPdfScalingFactor(1);
$pdfCrowd->setHtmlZoom(200);



If each of the set methods returned the object (for example: return $this;) the code would look like this:

$pdfCrowd = new Pdfcrowd;

$pdfCrowd->setPageWidth('11in')
         ->setPageHeight('8.5in')
         ->setPageMargins('.5in', '.5in', '.5in', '.5in')
         ->usePrintMedia(true)
         ->setInitialPdfZoomType(2)
         ->setPdfScalingFactor(1)
         ->setHtmlZoom(200);



A little cleaner and easier to read.
support wrote on 2013-11-18:
Hello,

Thank your for the tip, it is appreciated. We will consider adding it in future versions.
support wrote on 2017-11-22:
Hi,

the client for our new API supports this feature. So you can chain setters.
Here is the link for the new API:
https://pdfcrowd.com/api/html-to-pdf-php/
mermoris wrote on 2020-01-23:
Cool, is this in the latest version? Haven't used pdf crowd for a while.
support wrote on 2020-01-23:
Yes, it's in our clients starting the version 4.1.0