Shopware: Generating PDF with default font throws "Cannot find TTF TrueType font file "DejaVuSansMono.ttf"" - mpdf

I am using Mpdf v7 to generate a PDF file. This is my config:
$mpdfConfig =
[
'margin_left' => 25,
'margin_right' => 10,
'margin_top' => 20,
'margin_bottom' => 20,
'format' => 'A4-L',
'mode' => 'win-1252',
];
Calling the output to save my pdf throws the following error:
Cannot find TTF TrueType font file "DejaVuSansMono.ttf" in configured font directories.' in /var/www/html/vendor/mpdf/mpdf/src/Fonts/FontFileFinder.php on line 33
I'm using Shopware 5.5.1 and work with the included mpdf library. Calling the pdf with the following code:
$mpdf = new Mpdf($mpdfConfig);
$mpdf->WriteHTML($data);
$mpdf->Output($filename, "D");
Why is the DejaVuSansMono.ttf font not found? I do not use this font. Event with defining the 'default_font' to 'Courier' I get the same error.

Shopware is distributed with a modified version of mPDF with font files stripped (that this is a violation of its licence is another matter).
You have two or three options:
Instantiate mPDF with
$mpdf = new \Mpdf\Mpdf([
'mode' => 'c'
]);
configuration parameter which will use internal PDF fonts only
or to download or clone mPDF (from GitHub), move the ttfonts directory to your project and add the folder to mPDF configuration:
$mpdf = new \Mpdf\Mpdf([
'fontDir' => __DIR__ . '/ttfonts', // or similar
]);
or you can delete the vendor directory in your Shopware installation and recreate it by running composer install - that should recreate entire mPDF installatino with all fonts in the vendor directory but may cause other problems - I haven't tested this.

Related

How to set Airbrake with drupal 8

I'm trying to use Airbrake with my drupal 8 project, I follow this GitHub page https://github.com/akalsey/airbrake-drupal. I create an account and install the Airbrake using Composer composer require airbrake/phpbrake. Then it says that I should copy this snippet into your PHP app
$notifier = new Airbrake\Notifier(array(
'projectId' => ****,
'projectKey' => '****'
));
Airbrake\Instance::set($notifier);
$handler = new Airbrake\ErrorHandler($notifier);
$handler->register();
But I don't know in which file I past it?
Any help?

Drupal 8.6 Commerce: in .install file without module_uninstall() remove tables from database. Why?

When uninstall module then why delete all table from database without module_uninstall() function in .install file.
Also, why create table without module_install() function
.install file code is only:
function commerce_quickpay_schema() {
$schema['webc_crypto_meta'] = [
'description' => 'Custom Cryptography Meta',
'fields' => [...],
'primary key' => ['wcm_id'],
];
$schema['webc_crypto_payment'] = [
'description' => 'Custom Cryptography Payment',
'fields' => [...],
'primary key' => ['wcp_id'],
];
return $schema;
}
Also, please, CREATE TABLE IF NOT EXISTS condition in .install file.
This is how it behaves, the tables defined in hook_schema will be created or removed from the database when the module is installed or uninstalled, the hook_install() or hook_uninstall() hooks should be used when you want to do something extra.
It is simply assumed that the database schema should be removed when a module is uninstalled and come back when installed, if you think about it, it makes perfect sense.
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21database.api.php/function/hook_schema/8.7.x
"The tables declared by this hook will be automatically created when
the module is installed, and removed when the module is uninstalled.
This happens before hook_install() is invoked, and after
hook_uninstall() is invoked, respectively."

Symfony2 KNP Snappy IE9 give 0byte pdf & Firefox, Opera works

I am using the KNPSnappy Bundle with the Google Tool Wkhtml2pdf.
That is working with the Firefox 31 I use for the development (and Opera).
On our Company Computers is IE9 available.
With the IE I get an error:
There is the Question about open or save the file.
If I choose save it will tell note(3) couldn't be downloaded.
If I click retry it will freeze the IE.
I did check that the webpage is local internet with Low security level.
Working on an Centos/Apache Server.
Did not find an error in log off Apache or Symfony or Eventlog.
Where to find and information?
The File name 'note' that comes with error in IE is not the filename that was created in Firfox.
I did find the problem that was breaking the IE9.
The 201 as a response code was the problem just changed it to 200 and also the IE was working fine like the Firefox and the Opera did.
return new Response (
// use wkhtmltopdf options
$this->get ( 'knp_snappy.pdf' )->getOutputFromHtml ( $html, array (
'orientation' => 'Portrait',
'images' => true
) ), 201, array (
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="Invnr_' .$id. '.pdf"',
'Charset' => 'UTF-8',
'images' => true,
'print-media-type' => true
) );

laravel development environment sqlite database does not exist

Trying to use sqlite in development environment. It seems to detect the environment correctly but when I try to migrate to development.sqlite I get exception thrown "database does not exist"
artisan command
php artisan migrate --env=development
bootstrap/start.php
$env = $app->detectEnvironment(array(
'development' => array('localhost'),
));
app/config/development/database.php
<?php
return array(
'default' => 'sqlite',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/development.sqlite',
'prefix' => '',
)
)
);
As far as I know laravel is supposed to create the file if it does not exist but since it didn't I tried manually creating the file and still get the exception thrown.
UPDATE: Maybe something not right with the env because the same thing happens if I try ':memory' for the database.
UPDATE 2: I tried running the sample unit test but add to TestCase.php
/**
* Default preparation for each test
*
*/
public function setUp()
{
parent::setUp(); // Don't forget this!
$this->prepareForTests();
}
/**
* Creates the application.
*
* #return Symfony\Component\HttpKernel\HttpKernelInterface
*/
public function createApplication()
{
$unitTesting = true;
$testEnvironment = 'testing';
return require __DIR__.'/../../bootstrap/start.php';
}
/**
* Migrates the database and set the mailer to 'pretend'.
* This will cause the tests to run quickly.
*
*/
private function prepareForTests()
{
Artisan::call('migrate');
Mail::pretend(true);
}
And this too gives the same exception though the testing env is already shipped with laravel. So I'll see if I can find any new issues on that.
Wow, typos and wrong paths.
Copying the sqlite array from config/database.php into config/development/database.php I forgot to change the path to the development.sqlite file from
__DIR__.'/../database/development.sqlite'
to
__DIR__.'/../../database/development.sqlite'
And for the in memory test it should have been
':memory:'
instead of
':memory'
I noticed that my database.php file had the following
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
I changed it to read the following, and it worked just fine.
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
One of the problem which I faced was I use "touch storage/database.sqlite" in terminal, so database is created in Storage folder instead of database folder.
in my config/database.php path is database_path('database.sqlite')
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
'prefix' => '',
],
than I use command "php artisan migrate" which gave me error "Database (/Applications/MAMP/htdocs/FOLDER_NAME/database/database.sqlite) does
not exist."
so it's obvious database file is not in database folder as It was generated in Storage folder, so copy "database.sqlite" from storage folder or run command "touch database/database.sqlite"
Hope that helps.!!
Well, my answer is kinda outdated, but anyway. I faced the same problem, but with Laravel 5, I am using Windows 7 x64. First I manually created SQLite database called 'db' and placed it into storage directory, then fixed my .env file like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=oBxQMkpqbENPb07bLccw6Xv7opAiG3Jp
DB_HOST=localhost
DB_DATABASE='db'
DB_USERNAME=''
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null`
I thought it would fix my problems, but the command line keeps telling me that database doesn't exist. And then I just checked the path to db in my database.php file and this is why I put database file into storage directory. But nothing changed. And finally I checked db's extension and it was .db, not .sqlite as default extension you see in your sqlite block in database.php. So this is how I reconfigured sqlite piece:
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/db.db',
'prefix' => '',
],
And of course don't forget to set sqlite as default database in your database.php file. Good luck!
For me it was that path to database had to be '/var/www/html' + location to the database in your project. In my case database was stored in database/db.sqlite so DB_DATABASE='/var/www/html/database/db.sqlite'
I had the same error while running a GitHub action test workflow.
For me the solution was to define the relative path to the database archive into the workflow file:
on:
...
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
jobs:
laravel-tests:
...
I think that the previous answers reduce the importance of the config and most likely the developers wanted to get the database file like this:
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => database_path(env('DB_DATABASE', 'database').'.sqlite'), // <- like this
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
Tested on Laravel 9.x

How to generate translation file for a custom Drupal 7 module?

I'm using CentOS 5.5 Linux (without X), PHP 5.3 and Drupal 7.0.
The core language of my site is Russian (not English)!
I've created a game.info and the following game.module which generates 3 blocks for the front page:
function game_block_info() {
return array(
'game_main' => array(
'info' => t('Set FlashVars and show the flash game.'),
'cache' => DRUPAL_NO_CACHE,
),
'game_winner' => array(
'info' => t('Show the winner of the last week.'),
'cache' => DRUPAL_NO_CACHE,
),
'game_leader' => array(
'info' => t('Show the leader of the current week.'),
'cache' => DRUPAL_NO_CACHE,
);
}
function game_block_view($block_name = '') {
global $user;
if ($block_name == 'game_main') {
if (user_is_logged_in()) {
$content = t('User is logged in.');
} else {
$content = t('User is an anonymous user.');
}
drupal_set_message("<pre>$output</pre>\n");
return array(
'subject' => t('Main Game'),
'content' => $content,
);
} else if ($block_name == 'game_winner') {
....
} else if ($block_name == 'game_leader') {
....
}
}
It works ok, but I need all strings to be in Russian and do not want to hardcode them into my game.module file.
Do I need to create the 3rd file called game.po and add it to the game.info?
How can I create a .po file? I would prefer a simple editing of that file if possible, without obscure tools.
I've also tried a tool:
# xgettext -n game/game.module --keyword=t
xgettext: warning: file `game/game.module' extension `module' is unknown; will try C
game/game.module:87: warning: unterminated character constant
game/game.module:100: warning: unterminated character constant
These should be the steps:
To generate the .pot file, install the module Translation template extractor
Go to the "Extract strings" tab on the Locale administration interface, select your module and submit the form. You will get one single template file generated.
Then you can translate the strings with a tool like Poedit (http://www.poedit.net).
When you are done, files should be copied to a "translations" sub-folder in the module folder, so they are automatically imported by Drupal when installing your game module.
Please, give feedback and tell what problems did you have. Thanks

Resources