How to add digital signature certification in PDF using Laravel 6?

How to add digital signature certification in PDF using Laravel 6?

In this Laravel 6 tutorial, you'll learn how to create a PDF file with a digital signature certificate using Laravel 6. Learn step by step to create a PDF file with a digital signature certificate in the TCPDF library. TCPDF is an open-source PHP library and the only PHP-based library that includes complete support for UTF-8 Unicode and right-to-left languages, including the bidirectional algorithm.

TCPDF is an open-source PHP library and the only PHP-based library that includes complete support for UTF-8 Unicode and right-to-left languages, including the bidirectional algorithm.

In this article, we will step by step create PDF file with digital signature certificate in TCPDF library.

Step 1: Create Laravel project

First create Laravel project from the Terminal using bellow command.

composer create-project laravel/laravel tcpdf
Step 2: Install TCPDF library

We wil use **elibyy/tcpdf-laravel** package which makes simple and easy to use TCPDF in Laravel. You can also direct Install TCPDF package and use.

First go to the project root directory in Terminal and run the command.

composer require elibyy/tcpdf-laravel

It will install library in the vendor folder.

Step 3: Configure package

Open config/app.php file and add provider class in the providers array.

'providers' => [
    //...
    Elibyy\TCPDF\ServiceProvider::class,
]

Also add facade class in the aliases array.

'aliases' => [
    //...
    'PDF' => Elibyy\TCPDF\Facades\TCPDF::class
]
Step 4: Create new route

Now create route in **routes/web.php** file. Add this bellow line to create new URL.

<?php

Route::get('/tcpdf', '[email protected]')->name('createPDF');
Step 5: Create new controller class and method

Now create a new controller class with the bellow command.

php artisan make:controller HomeController

And add createPDF method in the **HomeController.php**. Don't forget to **use PDF** class in the top of the class declaration.

<?php

namespace App\Http\Controllers;

use PDF;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    public function createPDF(Request $request)
    {
        // set certificate file
        $certificate = 'file://'.base_path().'/public/tcpdf.crt';

        // set additional information in the signature
        $info = array(
            'Name' => 'TCPDF',
            'Location' => 'Office',
            'Reason' => 'Testing TCPDF',
            'ContactInfo' => 'http://www.tcpdf.org',
        );

        // set document signature
        PDF::setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info);

        PDF::SetFont('helvetica', '', 12);
        PDF::SetTitle('Hello World');
        PDF::AddPage();

        // print a line of text
        $text = view('tcpdf');

        // add view content
        PDF::writeHTML($text, true, 0, true, 0);

        // add image for signature
        PDF::Image('tcpdf.png', 180, 60, 15, 15, 'PNG');

        // define active area for signature appearance
        PDF::setSignatureAppearance(180, 60, 15, 15);

        // save pdf file
        PDF::Output(public_path('hello_world.pdf'), 'F');

        PDF::reset();

        dd('pdf created');
    }
}

See the available class methods to customize your PDF file. Output() method will save PDF file in the passed location.

Also check certificate location variable is prefix with **'file://',** otherwise it will return bellow error.

Step 6: Create blade view

We are also adding content of the blade file. I have added blade file in the view() method. You can also direct add html view content or via view() method. Here is my **resource/views/tcpdf.blade.php** file sample file.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>TCPDF</title>
</head>
<body>
    <p>
        This is a <b color="#FF0000">digitally signed document</b> using the default (example) <b>tcpdf.crt</b> certificate.<br />To validate this signature you have to load the <b color="#006600">tcpdf.fdf</b> on the Arobat Reader to add the certificate to <i>List of Trusted Identities</i>.<br /><br />For more information check the source code of this example and the source code documentation for the <i>setSignature()</i> method.<br /><br />
    </p>    
    <a href="http://www.tcpdf.org">www.tcpdf.org</a>
</body>
</html>
Step 7: Generate PDF file

That's it. Now run your Laravel project with php artisan serve command and open your route URL in the browser. A new PDF file is generated in the public folder.

To check if the certificate is installed perfectly, open PDF file in the **Adobe reader** in Windows operating system and click on the image bellow in the PDF document. It will load certificate.

Conclusion

There are so many features and customizations available in TCPDF. You can check I hope you will like this article.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

What’s new in HTML6

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Clear Cache in Laravel 6.8 App using Artisan Command Interface (CLI)

Clear Cache in Laravel 6.8 App using Artisan Command Interface (CLI)

In Laravel 6 tutorial, we learn how to use PHP artisan command interface (CLI) to clear the cache from Laravel 6.8 application. How To Clear Cache in Laravel 6.8 Application using Artisan Command Line Interface (CLI)? How to clear route cache using php artisan command? How to easily clear cache in Laravel application? How to clear config cache in PHP Laravel via artisan command? How to clear Laravel view cache? How to Reoptimized class in Laravel via artisan CLI?

Today in this tutorial, we are going to learn how to clear route cache, laravel application cache, config cache, view cache and reoptimized class in a Laravel 6.8 application using artisan command-line interface.

I’m pretty sure many of you may have found yourself gotten into the situation where you do not see changes in the view after making the changes in the app.

Laravel application serves the cached data so caching problem occurs due to the robust cache mechanism of Laravel.

But, if you are still facing this issue, then you do not have to worry further. Let me do the honour of introducing you some of the best artisan commands to remove the cache from your Laravel app via PHP artisan command line interface.

Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application.

Table of Contents

  • Clear Route Cache in Laravel
  • Clear Laravel Application Cache
  • Clear Config Cache via PHP Artisan
  • Clear Laravel View Cache
  • Reoptimized Class
Clear Route Cache in Laravel

Laravel caching system also takes routes in consideration, to remove route cache in Laravel use the given below command:

php artisan route:cache
Clear Application Cache in Laravel

Run the following command to clear application cache:

php artisan cache:clear
Clear Config Cache in Laravel

Run the following command to clear config cache:

php artisan config:cache
Clear View Cache in Laravel

Run the following command to clean your view cache:

php artisan view:clear
Reoptimize Class

Run the below command to reoptimize the class loader:

php artisan optimize

Conclusion

We have completed this Laravel 6 tutorial, In this tutorial we learned how to use php artisan command to clear the cache from your Laravel application. We have answered the following questions in this article.

  • How to clear route cache using php artisan command?
  • How to easily clear cache in Laravel application?
  • How to clear config cache in PHP Laravel via artisan command?
  • How to clear Laravel view cache?
  • How to Reoptimized class in Laravel via artisan CLI?

Now, it’s your time to let me know what do you think about this laravel 6 article. Go forth and try these super awesome artisan commands and let me know how these commands are helping you.

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather

Get Weather Data with Laravel Weather. Laravel Weather is a good package which we can use to get weather data. It's a wrapper around Open Weather Map API (Current weather). A wrapper around Open Weather Map API (Current weather)

🌤️ A wrapper around Open Weather Map API (Current weather)

Installation

You can install the package via composer:

source-shell
composer require gnahotelsolutions/laravel-weather
Usage
text-html-php
$weather = new Weather();

// Checking weather by city name
$currentWeatherInGirona = $weather->get('girona,es');

// You can use the city id, this will get you unambiguous results
$currentWeatherInGirona = $weather->find('3121456');

Units

By default the package uses metric for Celsius temperature results, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inUnits('imperial')->get('girona,es');

Language

By default the package uses es for the description translation, this can be modified using the configuration file or on the fly:

text-html-php
$weather = new Weather();

$currentWeatherInGirona = $weather->inLanguage('en')->get('girona');

Guzzle Client Instance

If you need to use another instance of Guzzle, to modify headers for example:

text-html-php
$weather = new Weather();

$guzzle = $this->getSpecialGuzzleClient();

$currentWeatherInGirona = $weather->using($guzzle)->get('girona');

Testing

source-shell
composer test

How to Use Sweet Alert in Laravel?

How to Use Sweet Alert in Laravel?

This Laravel tutorial explains how to use Sweet Alert in Laravel. Laravel SweetAlert is a Laravel package by Rashid Ali that integrates the popularJavaScript SweetAlert 2 library with Laravel. Sweet Alert is a Laravel wrapper around SweetAlert JavaScript library for showing alert or notification message.

This Laravel tutorial explains how to use Sweet Alert in Laravel. Laravel SweetAlert is a Laravel package by Rashid Ali that integrates the popularJavaScript SweetAlert 2 library with Laravel. Sweet Alert is a Laravel wrapper around SweetAlert JavaScript library for showing alert or notification message.

This is a great package created by rashid, and this laravel package is very famous because it has tonnes of features you can choose from.