How to install phpwkhtmltopdf - php

I am trying to install phpwkhtmltopdf on shared server (webhotel). The server has already composer installed, and I have SSH to server. But I am not too familiar with composer so I might be doing someting very basic wrong here..
So, I have downloaded the zip file from:
https://github.com/mikehaertl/phpwkhtmltopdf
and extracted the files on it to server to directory named as phpwkhtmltopdf.
Then, opening SSH cd-ing to that dir and running composer require mikehaertl/phpwkhtmltopdf but I only get question marks to beginning of line.
For the question marks I read that it could be a problem of detect unicode, so I placed to htaccess: php_flag detect_unicode Off and it seems that it is Off now locally.
But there is still the question marks and php wkhtmltopdf does not get installed. How to get it installed?

The problem is that you are fetching the package mikehaertl/phpwkhtmltopdf two times:
firstly, you fetched the zip and extracted it (manual installation).
then, you ran Composer to require it (installation via Composer).
Please decide how you want to install the package!
When you want to install the package with Composer, you just need to run composer require mikehaertl/phpwkhtmltopdf in a clean project folder.
Composer will then fetch the package and place it into the /vendor folder.
That's it.
Now, in order to use it you need two things:
you need to include Composers Autoloader during the bootstrap of your project. This enables that the Autoloader will load the library, when you access one the package/library classes.
// Register Composer Autoloader
define('VENDOR_DIR', __DIR__ . '\vendor' . DS);
if (!is_file(VENDOR_DIR . 'autoload.php')) {
throw new \RuntimeException(
'[Error] Bootstrap: Could not find "vendor/autoload.php".' . PHP_EOL .
'Did you forget to run "composer install --dev"?' . PHP_EOL
);
}
require VENDOR_DIR . 'autoload.php';
Well, finally, you need to code something using the library:
use mikehaertl\wkhtmlto\Pdf;
$pdf = new Pdf('/path/to/page.html');
if (!$pdf->saveAs('/path/to/page.pdf')) {
echo $pdf->getError();
}
Uhm, and you need the wkhtmltopdf binary... but i guess thats not the problem.
These are my steps:
i downloaded wkhtmltopdf http://download.gna.org/wkhtmltopdf/0.12/0.12.3.2/wkhtmltox-0.12.3.2_msvc2013-win64.exe
and installed it into c:\program files\wkhtmltopdf
now the executable resides in c:\program files\wkhtmltopdf\bin
i created the folder pdf-test
i ran the command composer require mikehaertl/phpwkhtmltopdf on the CLI
i created a file makepdf.php with the following content:
/**
* Register Composer Autloader
*/
define('VENDOR_DIR', __DIR__ . '\vendor' . DIRECTORY_SEPARATOR);
if (!is_file(VENDOR_DIR . 'autoload.php')) {
throw new \RuntimeException(
'[Error] Bootstrap: Could not find "vendor/autoload.php".' . PHP_EOL .
'Did you forget to run "composer install --dev"?' . PHP_EOL
);
}
require VENDOR_DIR . 'autoload.php';
/**
* Use library
*/
use mikehaertl\wkhtmlto\Pdf;
$pdf = new Pdf(array(
'binary' => 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe',
'ignoreWarnings' => true,
'commandOptions' => array(
'procEnv' => array(
// Check the output of 'locale' on your system to find supported languages
'LANG' => 'en_US.utf-8',
),
'escapeArgs' => false,
'procOptions' => array(
// This will bypass the cmd.exe which seems to be recommended on Windows
'bypass_shell' => true,
// Also worth a try if you get unexplainable errors
'suppress_errors' => true,
),
),
));
$pdf->addPage('<html>
<head>
</head>
<body>
<div id="print-area">
<div id="header">
This is an example header.
</div>
<div id="content">
<h1>Demo</h1>
<p>This is example content</p>
</div>
<div id="footer">
This is an example footer.
</div>
</div>
</body>
</html>');
if (!$pdf->saveAs('page.pdf')) {
echo $pdf->getError();
}
then i ran php makepdf.php
finally, the file page.pdf was generated
And that's it... :)

Related

How to disable "always include" class in Composer autoload_static.php

Composer in autoload_static.php use class that I don't need them in every app request.
'd5fa61a7f6cbc1df09dd4df84549a2dc' => __DIR__ . '/..' . '/rospdf/pdf-php/src/Cpdf.php',
'2d15964294879de66053d54f6bde65d7' => __DIR__ . '/..' . '/rospdf/pdf-php/src/Cezpdf.php',
How to remove them from this autoload file? I can delete/comment them manually but every Composer update this file is re-generated.
I try to add in my main composer.json:
"exclude-from-classmap": ["vendor/rospdf/pdf-php/src/"]
& run composer dump-autoload bo those class are still in there.
You can trick the autoloader of composer and let him think those are already loaded:
<?php
// Setting global variable:
$GLOBALS["__composer_autoload_files"] = [
"d5fa61a7f6cbc1df09dd4df84549a2dc" => true,
"2d15964294879de66053d54f6bde65d7" => true,
];
require "vendor/autoload.php";
But this needs to happen before the vendor/autoload.php is included.

How do I get CakePHP to load my <project_root>/src directory instead of vendor/maiconpinto/cakephp-adminlte-theme/src

Summary:
I'm a web and backend newb, but basically I've inherited a CakePHP project and I'm trying to set up a dev environment. I'm trying to display my project-level src directory at http://localhost/backend/, which autoroutes to http://localhost/backend/admin/users/dashboard, but it only loads PROJECT_ROOT/vendor/maiconpinto/cakephp-adminlte-theme/src.
Question:
How do I load my own sidebar using my top-level src directory? Thanks in advance!
Here's the desired sidebar: correct myteamconnector sidebar
Here's the sidebar that is getting loaded: incorrect vendor files sidebar
Setup Info:
System: Mac OS 10.14
Dev Apps:
AMPPS v3.8
Apache v2.4.27
PHP v7.1
MySQL v5.6.37
CakePHP v3.5.17
PROJECT_ROOT/index.php:
require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
PROJECT_ROOT/webroot/index.php:
// Check platform requirements
require dirname(__DIR__) . '/config/requirements.php';
// For built-in server
if (php_sapi_name() === 'cli-server') {
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
$url = parse_url(urldecode($_SERVER['REQUEST_URI']));
$file = __DIR__ . $url['path'];
if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
return false;
}
}
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Application;
use Cake\Http\Server;
// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/config'));
// Run the request/response through the application and emit the response.
$server->emit($server->run());
SOLVED
The issue was that the composer.json file was specifying "maiconpinto/cakephp-adminlte-theme": "^1.0" and therefore installing v1.1.0 which requires different implementations depending on the cakephp version being < or >=3.5.
So specifying "maiconpinto/cakephp-adminlte-theme": "1.0.8" in the composer.json file installed the previous version, which is compatible with the implementation in my repo.
For some reason in the working version there was a mismatch between the composer.json file and the vendor folder (i.e. the vendor folder contained a bunch of plugins that the composer.json file didn't have) allowing everything to work as long as you didn't run composer update, which my coworker hadn't done.

Composer with Koseven (Kohana)

I'm developing an application where I started using Kohana and now Koseven, and I need to use an api that was available in the composer, I followed the steps to download the files I created a folder to sell inside the application, and put in the bootstrap.php code to call the autoload of the composer.
But after doing this when trying to use a class of this api error of "class not found" occurs.
I do not know what else to do, can you help me?
In order to use composer with Kohana or Koseven, you need to call composer's autoloader from within bootstrap.php.
After Kohana::modules($modules); and before Route::set, insert the following code:
/**
* Autoload composer libraries
*
*/
require APPPATH . 'vendor/autoload.php';
This assumes your composer install command is run the from the root of your app, and it uses the default vendor directory.
Probably you must add this to your composer.json. (Check inc composer doc.) I don't know, because in modules directory I have second instance.
"extra": {
"installer-paths": {
"modules/{$name}/": ["type:kohana-module"]
}
},
And enable module composer as first:
Kohana::modules(array(
'composer' => MODPATH.'composer', //
'auth' => MODPATH.'auth', // Basic authentication
'cache' => MODPATH.'cache', // Caching with multiple backends
It works for me ko3

having difficulty setting up phpepub library

i have downloaded phpepub via composer
then started to run the test file to understand how to use the library but it throws an error
Class 'com\grandt\EPub' not found
and then i started to view the test folder and opened the file exampletest1.php which also threw an error saying that
Class 'PHPePub\Core\Logger' not found
i'm thinking a way of working out this error for a while now checked the privileges (which is fine) also the file is also present in the folder
here is the file structure of the library
phpepub/
legacy/
src/
PHPePub/
Core/
structure/
Logger.php
.
.
.
Helpers/
tests/
demo/
EPub.Example1.php
.
.
.
composer.json
vendor/
composer/
grandt/
phpzip/
.
.
.
README.md
test.php
ReadMe.html
.
.
.
.
composer.json
You need to require the vendor/autoload.php file in each file where you're using components installed using composer.
test.php :
<?php
require_once __DIR__.'/vendor/autoload.php';
//...
test/exampletest1.php
<?php
require_once __DIR__.'/../vendor/autoload.php');
//...
See Basic Usage - Autoloading in Composer Documentation.
Usage in your projects
In the root directory of your project, add "grandt/phpepub": ">=4.0.3" to your composer dependencies and run composer install.
Let's say your project directory structure is :
project
vendor
public
index.php
composer.json
When you run composer install, Composer creates a directory vendor/ in the project root and generates an autoload file vendor/autoload.php.
To use the installed libraries in index.php, require the autoload file :
index.php :
<?php
require_once __DIR__."/../vendor/autoload.php";
//...
For a quick detailed explanation, try reading Juan Treminio - Composer Namespaces in 5 minutes

Class 'yii\jui\DatePicker' not found (yii2 basic)

I downloaded the yii2-jui in this link
yii2-jui
After that I put it under yiisoft folder
yiisoft\yii2-jui
when I run my application it gives me this error
PHP Fatal Error – yii\base\ErrorException
Class 'yii\jui\DatePicker' not found
How can I fixed this.where should I put the yii2-jui folder ?
Thank you in advance
I fixed the problem when I ran
sudo composer require --prefer-dist yiisoft/yii2-jui "*"
ONLY IN FOLDER basic, where are web, yii, models and etc.
Insert this in the view:
use yii\jui\DatePicker;
The best way is: run: php composer.phar require --prefer-dist yiisoft/yii2-jui "*" in your project
insert code:
'yiisoft/yii2-jui' =>
array (
'name' => 'yiisoft/yii2-jui',
'version' => '2.0.2',
'alias' =>
array (
'#yii/jui' => $vendorDir . '/yiisoft/yii2-jui',
),
),
in yiisoft/extensions.php file
Stop creating duplicate questions.
And you do not just download something and copy it in a folder. Use composer to install it. the Yii2 that you copied is just a shell, you have to use composer to install the rest of it. Composer does more then just copy the files it creates an autoloader that tells yii where everything is.

Categories