{"action":"created","issue":{"url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/109","labels_url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/109/comments","events_url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/109/events","html_url":"https://github.com/mikehaertl/phpwkhtmltopdf/pull/109","id":91299258,"number":109,"title":"Allow to view raw pdf contents","user":{"login":"tomfotherby","id":140179,"avatar_url":"https://avatars.githubusercontent.com/u/140179?v=3","gravatar_id":"","url":"https://api.github.com/users/tomfotherby","html_url":"https://github.com/tomfotherby","followers_url":"https://api.github.com/users/tomfotherby/followers","following_url":"https://api.github.com/users/tomfotherby/following{/other_user}","gists_url":"https://api.github.com/users/tomfotherby/gists{/gist_id}","starred_url":"https://api.github.com/users/tomfotherby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomfotherby/subscriptions","organizations_url":"https://api.github.com/users/tomfotherby/orgs","repos_url":"https://api.github.com/users/tomfotherby/repos","events_url":"https://api.github.com/users/tomfotherby/events{/privacy}","received_events_url":"https://api.github.com/users/tomfotherby/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-26T16:57:21Z","updated_at":"2015-06-27T08:23:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/pulls/109","html_url":"https://github.com/mikehaertl/phpwkhtmltopdf/pull/109","diff_url":"https://github.com/mikehaertl/phpwkhtmltopdf/pull/109.diff","patch_url":"https://github.com/mikehaertl/phpwkhtmltopdf/pull/109.patch"},"body":"Hi @mikehaertl \r\n\r\nToday I wanted to send a email with a PDF attachment using [apostle.io](https://github.com/apostle/apostle-php) which require the contents of the attachment as a string, e.g.\r\n\r\n```php\r\n$mail = new Mail(\"template-slug\");\r\n$mail->addAttachment(\"test.txt\", \"Some test text\");\r\n$mail->deliver();\r\n```\r\nCorrect me if I'm wrong but in `phpwkhtmltopdf` v2.0.4, we're not able to capture the PDF contents into a variable. i.e. this won't work because it's dumped to stdout including some headers:\r\n\r\n```php\r\n        $pdf = new mikehaertl\\wkhtmlto\\Pdf();\r\n        $pdf->addPage('<html>A PDF Test page</html>');\r\n        if (($pdfText = $pdf->send()) === false) {\r\n            echo \"Could not create PDF Test Page\".$pdf->getError().\"\\n\";\r\n        }\r\n```\r\nI found if I added the following function to `Pdf.php`:\r\n\r\n```php\r\n    /**\r\n     * view raw PDF contents\r\n     */\r\n    public function raw()\r\n    {\r\n        if (!$this->_isCreated && !$this->createPdf()) {\r\n            return false;\r\n        }\r\n        return file_get_contents($this->_tmpPdfFile->getFileName());\r\n    }\r\n```\r\nThen it suited my purposes and I could use it like this:\r\n\r\n```php\r\n        $pdf = new mikehaertl\\wkhtmlto\\Pdf();\r\n        $pdf->addPage('<html>A PDF Test page</html>');\r\n        if (($pdfText = $pdf->raw()) === false) {\r\n            echo \"Could not create PDF Test Page\".$pdf->getError().\"\\n\";\r\n        }\r\n```\r\n\r\nWould you consider adding my `raw()` function? I opened a pull request in case it helps but let me know if you have a better implementation (from my experience you always do :smile_cat:  ) . i.e. feel free to ignore me, or propose changes that I can help with."},"comment":{"url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/comments/115984161","html_url":"https://github.com/mikehaertl/phpwkhtmltopdf/pull/109#issuecomment-115984161","issue_url":"https://api.github.com/repos/mikehaertl/phpwkhtmltopdf/issues/109","id":115984161,"user":{"login":"mikehaertl","id":675062,"avatar_url":"https://avatars.githubusercontent.com/u/675062?v=3","gravatar_id":"","url":"https://api.github.com/users/mikehaertl","html_url":"https://github.com/mikehaertl","followers_url":"https://api.github.com/users/mikehaertl/followers","following_url":"https://api.github.com/users/mikehaertl/following{/other_user}","gists_url":"https://api.github.com/users/mikehaertl/gists{/gist_id}","starred_url":"https://api.github.com/users/mikehaertl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikehaertl/subscriptions","organizations_url":"https://api.github.com/users/mikehaertl/orgs","repos_url":"https://api.github.com/users/mikehaertl/repos","events_url":"https://api.github.com/users/mikehaertl/events{/privacy}","received_events_url":"https://api.github.com/users/mikehaertl/received_events","type":"User","site_admin":false},"created_at":"2015-06-27T08:23:22Z","updated_at":"2015-06-27T08:23:22Z","body":"Hey Tom,\r\n\r\nseems like this becomes a frequently requested feature :) (see #102). How about adding your method as `__toString()` instead? Then you could do something like:\r\n\r\n```\r\n$pdf = new mikehaertl\\wkhtmlto\\Pdf();\r\n$pdf->addPage('<html>A PDF Test page</html>');\r\n$rawPdfContent = (string) $pdf;\r\n```\r\n\r\nWould this help?"}}