{"id":14974701,"url":"https://github.com/daudmalik06/phpchrometopdf","last_synced_at":"2025-04-05T03:11:13.458Z","repository":{"id":56963692,"uuid":"96417180","full_name":"daudmalik06/PhpChromeToPdf","owner":"daudmalik06","description":"A slim PHP wrapper around Google Chrome for converting URLs to PDFs or taking screenshots. It's easy to use and has a clean OOP interface. Compatible with Laravel, Symfony, and other frameworks. It resolves CSS/HTML issues when generating PDFs/images.","archived":false,"fork":false,"pushed_at":"2024-01-10T15:21:49.000Z","size":47,"stargazers_count":148,"open_issues_count":1,"forks_count":21,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-29T02:06:51.695Z","etag":null,"topics":["browsershot","chrome","chromium","headless","headless-browsers","headless-chrome","laravel","laravel-framework","pdf","pdf-generation","php","screenshot","symfony","url-to-image","url-to-pdf"],"latest_commit_sha":null,"homepage":"https://github.com/daudmalik06/PhpChromeToPdf","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daudmalik06.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-06T10:10:36.000Z","updated_at":"2025-01-22T18:08:21.000Z","dependencies_parsed_at":"2024-06-21T13:14:31.033Z","dependency_job_id":"1766ee59-13da-4e08-a2d7-e75e7c2052c2","html_url":"https://github.com/daudmalik06/PhpChromeToPdf","commit_stats":{"total_commits":30,"total_committers":6,"mean_commits":5.0,"dds":"0.30000000000000004","last_synced_commit":"b7ff64440f04d0427138a6475c6b0d0b3958de78"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daudmalik06%2FPhpChromeToPdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daudmalik06%2FPhpChromeToPdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daudmalik06%2FPhpChromeToPdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daudmalik06%2FPhpChromeToPdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daudmalik06","download_url":"https://codeload.github.com/daudmalik06/PhpChromeToPdf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browsershot","chrome","chromium","headless","headless-browsers","headless-chrome","laravel","laravel-framework","pdf","pdf-generation","php","screenshot","symfony","url-to-image","url-to-pdf"],"created_at":"2024-09-24T13:50:57.437Z","updated_at":"2025-04-05T03:11:13.443Z","avatar_url":"https://github.com/daudmalik06.png","language":"PHP","readme":"PHP ChromeToPdf\n===============\n\n[![Latest Stable Version](https://poser.pugx.org/dawood/phpchromepdf/v/stable.svg)](https://packagist.org/packages/dawood/phpchromepdf)\n[![Total Downloads](https://poser.pugx.org/dawood/phpchromepdf/downloads)](https://packagist.org/packages/dawood/phpchromepdf)\n[![License](https://poser.pugx.org/dawood/phpchromepdf/license.svg)](https://packagist.org/packages/dawood/phpchromepdf)\n\n\nPHP ChromeToPdf provides a simple and clean interface to ease PDF and image creation with\n[Google Chrome](https://www.google.com/chrome/). **The `Google Chrome`\nmust be installed and working on your system.** See the section below for details.\n\n\n## History\nEvery time i had convert url to pdf or to take screenshot of some url\ni had to install several libraries , i know there are very good libraries available\nlike phantomJs,wkhtmltopdf and some others...\nbut there are always rendering issue  \nlike some supports **bootstrap** ,some not some time **html5 problem** etc..  \nand this was all annoying\nso i decided to make this little wrapper around chrome  \nby using chrome results i achieved following results.  \n* **No more css issues (bootstrap,css3 )**\n* **No more html5 issues**\n* **No more need to use xvfb**\n\n**in-fact painless conversion**\n\n\n## Installation ( Laravel )\nThis package supports Laravel. Install it in a Laravel application as follows:\n\n```\ncomposer require dawood/phpchromepdf\n```\n\ndone.\n\n## Installation ( Simple PHP App )\n\nInstall the package through [composer](http://getcomposer.org):\n\n```\ncomposer require dawood/phpchromepdf\n```\n\nMake sure, that you include the composer [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading)\nsomewhere in your codebase.\n\n## Examples\nThere are several examples provided in examples folder too\n\n\n### Url To PDF (accessing site as  bigger browser)\n\n```php\n\nuse dawood\\phpChrome\\Chrome; \n\n\n$chrome=new Chrome('https://youtube.com','/usr/bin/google-chrome');\n$chrome-\u003esetOutputDirectory(__DIR__);\n//not necessary to set window size\n$chrome-\u003esetWindowSize($width=1477,$height=768);\nprint \"Pdf successfully generated :\".$chrome-\u003egetPdf().PHP_EOL;\n\n\n\n```\n\n\n### Url To PDF (accessing site as  mobile browser)\n\n```php\n\nuse dawood\\phpChrome\\Chrome;\n\n$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');\n$chrome-\u003esetOutputDirectory(__DIR__);\n$chrome-\u003euseMobileScreen();\n//not necessary to set window size\n$chrome-\u003esetWindowSize($width=768,$height=768);\nprint \"Pdf successfully generated :\".$chrome-\u003egetPdf().PHP_EOL;\n\n```\n\n\n### Take screenshot of url (accessing site as  bigger browser)\n\n```php\n\nuse dawood\\phpChrome\\Chrome;\n\n\n$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');\n$chrome-\u003esetOutputDirectory(__DIR__);\n//not necessary to set window size\n$chrome-\u003esetWindowSize($width=1366,$height=1024);\nprint \"Image successfully generated :\".$chrome-\u003egetScreenShot().PHP_EOL;\n\n\n\n```\n\n### Take screenshot of url (accessing site as  mobile browser)\n\n```php\n\nuse dawood\\phpChrome\\Chrome;\n\n\n$chrome=new Chrome('https://facebook.com','/usr/bin/google-chrome');\n$chrome-\u003esetOutputDirectory(__DIR__);\n$chrome-\u003euseMobileScreen();\n\n//not necessary to set window size\n$chrome-\u003esetWindowSize($width=768,$height=768);\nprint \"Image successfully generated :\".$chrome-\u003egetScreenShot().PHP_EOL;\n\n\n```\n\n### Take screenshot of Html File\n\n```php\n\ninclude '../vendor/autoload.php';\n\nuse dawood\\phpChrome\\Chrome;\n\n$chrome=new Chrome(null,'/usr/bin/google-chrome');\n$chrome-\u003euseHtmlFile(__DIR__.'/index.html');\nprint \"Image successfully generated :\".$chrome-\u003egetScreenShot().PHP_EOL;\n\n\n\n```\n\n### convert Html file to pdf\n```php\n\ninclude '../vendor/autoload.php';\n\nuse dawood\\phpChrome\\Chrome;\n\n$chrome=new Chrome(null,'/usr/bin/google-chrome');\n$chrome-\u003euseHtmlFile(__DIR__.'/index.html');\nprint \"Pdf successfully generated :\".$chrome-\u003egetPdf().PHP_EOL;\n\n\n```\n\n\n### convert Html code to pdf / screenshot\n```php\n\ninclude '../vendor/autoload.php';\n\nuse dawood\\phpChrome\\Chrome;\n\n$chrome=new Chrome(null,'/usr/bin/google-chrome');\n$chrome-\u003euseHtml(\"\u003ch2\u003eI am test html\u003c/h2\u003e\");\nprint \"Pdf successfully generated :\".$chrome-\u003egetPdf().PHP_EOL;\nprint \"screenShot successfully generated :\".$chrome-\u003egetScreenShot().PHP_EOL;\n\n\n```\n\n### convert Html code to pdf / screenshot and save at desired location\n```php\n\ninclude '../vendor/autoload.php';\n\nuse dawood\\phpChrome\\Chrome;\n\n$chrome=new Chrome(null,'/usr/bin/google-chrome');\n$chrome-\u003euseHtml(\"\u003ch2\u003eI am test html\u003c/h2\u003e\");\nprint \"Pdf successfully generated :\".$chrome-\u003egetPdf(\"/tmp/mypdf.pdf\").PHP_EOL;\nprint \"screenShot successfully generated :\".$chrome-\u003egetScreenShot(\"/tmp/hello/test.jpg\").PHP_EOL;\n\n\n```\n\n\n\n## Setting options\n\nThe `google-chrome` shell command accepts different types of options:\nfor complete list of options you can visit\nhttps://peter.sh/experiments/chromium-command-line-switches/\n\n\n\n### Wrapper Methods\n\n\n * `constructor`: Accepts $url to visit(for pdf/screenshot) as first parameter\n you can pass this as null and later use `setUrl`, and second parameter is binary\n path of google-chrome installed in your system as second parameter if no binaryPath is provided\n is uses default location `/usr/bin/google-chrome`\n but you still can provide binary path later using `setBinaryPath`,\n constructor also put some default arguments like\n `headless , disable-gpu` which are necessary for google-chrome to work on cli\n * `setBinaryPath` which accepts binary path and set it for you\n * `setArguments` to set options of google-chrome it accepts array of options in a format\n ```\n [\n    $argument1=\u003e$value1,\n    $argument2=\u003e$value2,  \n ]\n ```\nif your argument doesn't has values like `--headless` you can pass empty value\n e.g\n `[--headless=\u003e'']`\n* `setArgument` to set option of google-chrome it accepts two parameter $argument , $value\n if your argument doesn't has a value like `--headless` you can pass empty value e.g\n `setArgument('--headless','')`\n\n* `setChromeDirectory` the directory where google-chrome will save your profile\n    it is not mandatory as google-chrome by default uses some directory but in need\n    you can use this method to change that\n* `setUrl` to set the url to convert to pdf or to take screenshot    \n\n* `useHtmlFile` to use the file instead of url to convert to pdf or to take screenshot    \n\n* `useHtml` to use the html code instead of url to convert to pdf or to take screenshot    \n\n* `setOutputDirectory` directory to save the output (screenshots and pdf) the\ndefault directory is temporary directory of your operating system\n\n* `getPdf` it receives optional path parameter to save the pdf file at\nif not provided it will save in output directory or temp directory of your\noperating system depending if you properly set up the output directory,  \nfor this check `setOutputDirectory` option,  \nit will convert your provided url to pdf and return the\nlocation of newly saved pdf\n\n* `getScreenShot` it receives optional path parameter to save the pdf file at\nif not provided it will save in output directory or temp directory of your\noperating system depending if you properly set up the output directory  \nfor this check `setOutputDirectory` option,  \nit will take screenshot of your provided url and return the\nlocation of newly saved image\n\n* `setWindowSize` you can set the chrome window size using this method\nit accepts two parameters $width and $height\n\n* `useMobileScreen` ask chrome to access site as mobile browser\n\n* `getArguments` returns all the arguments set\n\nthere are some other getters available too in case you need\n `getUrl , getBinaryPath , getOutputDirectory`\n\n\n\n\n\n## Installation of google-Chrome (linux/mac )\n```shell\nwget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -\nsudo sh -c 'echo \"deb http://dl.google.com/linux/chrome/deb/ stable main\" \u003e\u003e /etc/apt/sources.list.d/google.list'\n\nsudo apt-get install libxss1 libappindicator1 libindicator7 libosmesa6\n\nsudo apt-get update\nsudo apt-get install -y google-chrome-stable\n\nsudo ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so\n\n```\n\nthen try running `google-chrome` from shell to verify it's installation\n\n\n\n## Installation of google-Chrome (Windows)\n```\nJust Install updated version of chrome(after V 61.*)  \nthat-s it\n```\n\nthen try running `C:\\Program Files (x86)\\Google\\Chrome\\Application\u003echrome.exe --headless` from cmd terminal to verify it's installation  \n\n\u003e Note  the path of chrome directory can be different in your case  \n\n## License\nThe **PhpChromeToPdf** is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n## Contribution\nThanks to all of the contributors ,  \nCheck [Contribution](CONTRIBUTING.md) for contribution rules\n\n## Author\nDawood Ikhlaq and Open source community\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaudmalik06%2Fphpchrometopdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaudmalik06%2Fphpchrometopdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaudmalik06%2Fphpchrometopdf/lists"}