Coder Social home page Coder Social logo

laravel-fpdf's Introduction

Laravel package for Fpdf

Latest Stable Version Total Downloads StyleCI License

Using FPDF made easy with Laravel. See FPDF homepage for more information about the usage.

Installation using Composer

composer require codedge/laravel-fpdf

Configuration

Run
php artisan vendor:publish --provider="Codedge\Fpdf\FpdfServiceProvider" --tag=config
to publish the configuration file to config/fpdf.php.

Usage

// app/Http/routes.php | app/routes/web.php

Route::get('/', function (Codedge\Fpdf\Fpdf\Fpdf $fpdf) {

    $fpdf->AddPage();
    $fpdf->SetFont('Courier', 'B', 18);
    $fpdf->Cell(50, 25, 'Hello World!');
    $fpdf->Output();
    exit;

});

Defining fonts

FPDF comes with a set of fonts already defined and stored in the src/Fpdf/font directory. If you want to add your own font, please have a look at the Adding new fonts and encodings tutorial.

You can change the font path, by using the FPDF_FONTPATH environment variable.

Use in Laravel Vapor

If you want to use Laravel Vapor to host your application, a special header needs to be attached to each response that FPDF returns to your browser. To enable the use of this header, add the following environment variable to the Vapor environment file:

FPDF_VAPOR_HEADERS=true

laravel-fpdf's People

Contributors

benjivm avatar camerontucker avatar codedge avatar davidoskay avatar dependabot[bot] avatar dniccum avatar erikn69 avatar laravel-shift avatar mansoorkhan96 avatar no-simpler avatar oscar-ol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-fpdf's Issues

Custom Headers and footers

I've been using Fpdf for a number of years, so I was excited to see this package in Laravel. (one less thing to learn from scratch)
I'm following your direction to edit the header() and footer() functions by creating a pdf Model and overwriting the functions. (issue #11)

However, I will need to do this to many separate Documents, which will contain a different header and footer. Is there a simple way to do this, or would it make more sense to Kill auto page break and insert them manually?

Compatibility Laravel 11

OMG I am waiting a week or more to update to Laravel 11 and I cant because I need this package....
I think we move to Dompdf.
Im sorry, but you dont update yet.

Laravel 5.3 Class Not found

After updating composer with required packages and registering in config/app.php, I've tried laravel-fpdf in laravel 5.3,

        composer.json
       "require": {
           .....
          "codedge/laravel-fpdf": "^1.0"
         },

         providers
        Codedge\Fpdf\FpdfServiceProvider::class, 
       
        aliases
        'Fpdf' => Codedge\Fpdf\Facades\Fpdf::class, 

simply in web.php routes like

Route::get('GeneratePdf', function (Codedge\Fpdf\Fpdf\FPDF $fpdf) {

	$fpdf->AddPage();
	$fpdf->SetFont('Courier', 'B', 18);
	$fpdf->Cell(50, 25, 'Hello World!');
	$fpdf->Output();

});

And I'm getting error

ReflectionException in Route.php line 339:
Class Codedge\Fpdf\Fpdf\FPDF does not exist

What could possibly be wrong ?

Decoding?

Hi,
I have just installed the fpdf, and when I output 'hello world' example, I get a text that is not decoded.

fpdf

easyTable

Hi ,

switching an app from Codeigniter 3 to Laravel and stuck on using this library :
fpdf-easytable/fpdf-easytable

Any way to use this library on this package ? In CI it was pretty easy to implement
but here with composer I'm kinda lost and haven't figured out which way to go yet.
Do I need to edit FpdfServiceProvider.php for this or there is some other way to use it ?

Thanks.

Digital data is gone missing when trying to update the pdf.

I am trying to add an image to the pdf which have some digital data in it. (Some field are filled from "Zoho Sign", "Docusign").
I am able to generate the pdf with that image in it. But the digital data is gone missing.

Is there are any way to get the digital data with the pdf?
Please help me to sort this problem.

The Code, I used, is shown below:
`
use setasign\Fpdi\Fpdi;

$pdf = new FPDI();
$pdf->setSourceFile('uploads/document_name.pdf');
$pagecount = $pdf->setSourceFile('uploads/document_name.pdf');

for ($i = 0; $i < $pagecount; $i++) {

// Adding the Pages
$pdf->AddPage();

$tpl = $pdf->importPage($i + 1, '/MediaBox', true);
$pdf->useTemplate($tpl, 0, 0, 208);
$pdf->Rect(0, 0, 210, 295, 'D');

$pdf->Image($image, 90, 170, -450);
}

$pdf->Output('D');
`

Laravel 8 no text Output

Hello, I have this module in another project with Laravel 7. Everything works great. In my current project I use Laravel 8 and unfortunately I don't get any text in the generated PDF. However, formatting the page size or adding pages works. Unfortunately, I also get no PHP errors to give further input.

Since this plugin has Laravel 9 support, I assume that Laravel 8 also supports it?

problem during installation

Hello, how are you? first of all thanks for this dependency.
I'm having this problem with the installation:

C:\xampp\htdocs\SIA - Copia>composer require codedge/laravel-fpdf
Using version ^1.7 for codedge/laravel-fpdf
./composer.json has been updated
Running composer update codedge/laravel-fpdf
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires codedge/laravel-fpdf ^1.7 -> satisfiable by codedge/laravel-fpdf[1.7.0].
- codedge/laravel-fpdf 1.7.0 requires illuminate/support ^6.0|^7.0|^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but it conflicts with another require.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Getting this text when I output the pdf in laravel

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T0��30P�ISp � ����Z�������(hx����+����(j*�d������Q endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0��

Unsupported operand types: string / float

I am getting the subject error from the following line

$this->FontSize = $size/$this->k;

The error is obviously in Fpdf and the solution would be to covert size to int first before performing the operation e.g but are wondering if the PR should be raised here or upstream.

$this->FontSize = intval($size)/$this->k;

Failed to install

[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 16:
...^1.5", }, "require-dev"
--------------------^
Expected: 'STRING' - It appears you have an extra trailing comma

Orientation Page()

By default the sheet is placed in vertical mode
when I type this to show me the horizontal mode: $ this-> pdf = new Fpdf ('L', 'mm', 'A4');
It shows me an error in this line, but if I remove it, the normal report
I need your help

Laravel 5.4 Class not found pls Help

I insall Package like in readme md but every time if i open rote get error "Codedge\Fpdf\FpdfServiceProvide" get this errror many times if i will requier package from github, i do composer dump-autoload try with writing each fpdf.php in uppercase, but it not work. Can somebody help me...

Header or footer not showing up.

I have this in web routes
Route::get('/fpdf', 'myController@method');
Then inside myController

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Fpdf;

class PDF extends Fpdf {
    function Header() {
    	$this->Image(storage_path() . 'logo.png',10,6,30);
    	$this->SetFont('Arial','B',15);
    	$this->Cell(80);
    	$this->Cell(30,10,'Title',1,0,'C');
    	$this->Ln(20);
    }
    function Footer() {
    	$this->SetY(-15);
    	$this->SetFont('Arial','I',8);
    	$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    }
}

class myController extends Controller {
    public function method() {
    	$pdf = new PDF();
    	$pdf::AliasNbPages();
    	$pdf::AddPage();
    	$pdf::SetFont('Times','',12);

    	for($i=1;$i<=40;$i++)
    	    $pdf::Cell(0,10,'Printing line number '.$i,0,1);

	    $pdf::Output();
	    exit;
    }
}

The header and footer are not showing up only the main section. I don't see any errors.
Thanks.

Installation and README clarification

In order to publish the config file:

php artisan vendor:publish --provider="Codedge\Fpdf\FpdfServiceProvider" --tag=config

you must first register the service provider. In your installation procedures you list the above command to run after the composer require command.

For future users you should simply add registering the service provider instructions before the config command in your README.

Class 'Fpdf' not found

I already install and setting usage in config/app.php

I want use fpdf
Class 'Fpdf' not found

Problems with the headers.

Hello!
This script doesn't really work correctly on Laravel 5.5

When i did everything and try to test it, it doesn't actually create the pdf headers.
From the "Hello World" demo, the only thing that i see is this:

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T0��30P�ISp � ����Z�������(hx����+����(j�d������Q endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0����>���L��%�DI�8���~�%E��r�ﻻvҪHX�gvVk?/����Ῑ��`�]�[��x5 �3\z��P�}�����PO���j���Jݍ^���x6/f��������������|����4}�z�������}����@�,ۖ-��˺E�u���^�,���<� �Z_�K� �IQ�����Yd�����C�K�_�%q�8>���!�J"V!�2&bGģ%r"H��D��}2EL1n����h�j����e���"�a*�H����:���d���9c���[�X�1~��"�3�g���Ñ�;O��> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R >> /XObject << >> >> endobj 7 0 obj << /Producer (FPDF 1.81) /CreationDate (D:20180904171808) >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 9 0000000000 65535 f 0000000230 00000 n 0000000867 00000 n 0000000009 00000 n 0000000087 00000 n 0000000317 00000 n 0000000751 00000 n 0000000971 00000 n 0000001047 00000 n trailer << /Size 9 /Root 8 0 R /Info 7 0 R >> startxref 1096 %%EOF

So what i have to change, to work correctly?

Multiple PDF's

Hi,

How does one create multiple pdfs?
Example of what I'm trying to do:

    foreach ($orders as $order) {

        $orderPdf = new Fpdf('P','mm','A4');
        $orderPdf::AddPage();
        .....
        $orderPdf::Output('F', '...');

    }

But this results in a an Exception
FPDF error: The document is closed

Many thanks !

> endobj 2 0 obj

Hi i need help with this error

image

In my controller i have this

image

I hope prompt help. Regards

Encode character UTF8

Hi guys,

I installed this package for my website, pdf exported will contains the name of the logged users. All french accents are correctly encoded with utf8_decode function but some czech accents are not correctly encoded as the name 'Vojtěch' .

Is there any way to do it ? I wanted to change font with custom one but it doesn't seems possible.

Thanks,
Antoine

I got this error please tellme how to solve thant..... i am using laravel 5.3...and xampp

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�3R��2�35W(�r Q�w3T0��30P�ISp � ����Z�������(hx����+����(j�d������Q endstream endobj 1 0 obj <> endobj 5 0 obj <> stream x�]R�n�0����>���L��%�DI�8���~�%E��r�ﻻvҪHX�gvVk?/����Ῑ��`�]�[��x5 �3\z��P�}�����PO���j���Jݍ^���x6/f��������������|����4}�z�������}����@�,ۖ-��˺E�u���^�,���<� �Z_�K� �IQ�����Yd�����C�K�_�%q�8>���!�J"V!�2&bGģ%r"H��D��}2EL1n����h�j����e���"�a*�H����:���d���9c���[�X�1~��"�3�g���Ñ�;O��> endobj 2 0 obj << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI] /Font << /F1 6 0 R >> /XObject << >> >> endobj 7 0 obj << /Producer (FPDF 1.81) /CreationDate (D:20170302202830) >> endobj 8 0 obj << /Type /Catalog /Pages 1 0 R >> endobj xref 0 9 0000000000 65535 f 0000000230 00000 n 0000000867 00000 n 0000000009 00000 n 0000000087 00000 n 0000000317 00000 n 0000000751 00000 n 0000000971 00000 n 0000001047 00000 n trailer << /Size 9 /Root 8 0 R /Info 7 0 R >> startxref 1096 %%EOF

new release tag

Could you add a new release tag so we can use: "codedge/laravel-fpdf": "^1.3", with laravel 6

I don't like to add master as a version

PHP 7.3 & Laravel 7

Laravel 7 is released on 3rd March - provide support for this. Furthermore 7.2 is an old, although supported version. Regardless I am dropping support for this. #pushingforward

Support Laravel 9

wbeta@Laptop-WRBD MINGW64 /d/Projects Laravel - Livewire/Projects/idept.edu.pe - IDEPT System
$ composer require codedge/laravel-fpdf
Using version ^1.8 for codedge/laravel-fpdf
./composer.json has been updated
Running composer update codedge/laravel-fpdf
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires codedge/laravel-fpdf ^1.8 -> satisfiable by codedge/laravel-fpdf[1.8.0].
- codedge/laravel-fpdf 1.8.0 requires illuminate/support ^6.0 || ^7.0 || ^8.0 -> found illuminate/support[v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require codedge/laravel-fpdf:*" to figure out if any version is installable, or "composer require codedge/laravel-fpdf:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Missing exit; in the sample code

Hi there!
Great work thanks! I just want to tell you, that it works for me only if I put an exit; after the code. I am using Laravel 5.8. So the final code is:
$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
exit;

Exception not found

We get the following error on one of our sites.

(1/1) FatalErrorExceptionClass 'Codedge\Fpdf\Fpdf\Exception' not found
--
in Fpdf.php (line 271)

PHP: 5.6.30
Fpdf: 1.2

composer.json

    "require": {
        "php": ">=5.6.4",
        "backpack/base": "^0.7.19",
        "backpack/crud": "^3.2",
        "backpack/langfilemanager": "^1.0",
        "backpack/permissionmanager": "^2.1",
        "codedge/laravel-fpdf": "^1.2",
        "doctrine/dbal": "^2.5",
        "kalnoy/nestedset": "^4.3",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },
    "require-dev": {
        "backpack/generators": "^1.1",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7",
        "laracasts/generators": "dev-master as 1.1.4"
    },
...

NEW WAY TO WORK

I have used your code it did not work.. Anyhow we should pass it through response

Fpdf::AddPage();
Fpdf::SetFont('Courier', 'B', 18);
Fpdf::Cell(50, 25, 'Hello World!');
// Fpdf::Output();
return response(Fpdf::Output(), 200)->header('Content-Type', 'application/pdf');

issue of generated pdf file

$objPdf = new Fpdf;
$objPdf->AddPage();
$objPdf->SetFont('Arial', '', 10);
$objPdf->SetTitle("Title");
$objPdf->SetAuthor('Author');
$objPdf->Cell(50, 25, 'Hello World!');
$objPdf->AliasNbPages();
$objPdf->Output("","i");
ob_get_clean();

this is my code but generated pdf file not display on browser , but when I replace $objPdf->Output("","i"); by $objPdf->Output("","f"); it works good and save file on server . so what is the problem here and thanks

How to extend FPDF class

I want to extend FPDF class so that I can override functions(header & footer).

code
`class PDF extends FPDF
{
function Header()
{
global $title;

// Arial bold 15
$this->SetFont('Arial','B',15);
// Calculate width of title and position
$w = $this->GetStringWidth($title)+6;
$this->SetX((210-$w)/2);
// Colors of frame, background and text
$this->SetDrawColor(0,80,180);
$this->SetFillColor(230,230,0);
$this->SetTextColor(220,50,50);
// Thickness of frame (1 mm)
$this->SetLineWidth(1);
// Title
$this->Cell($w,9,$title,1,1,'C',true);
// Line break
$this->Ln(10);

}

function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Text color in gray
$this->SetTextColor(128);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}}`

Add scripts

How can I add scripts.
I have added them to the /vendor/codedge/laravel-fpdf/src/Fpdf folder.
e.g.: code128.php http://www.fpdf.org/en/script/script88.php
In my controller instead of
use Codedge\Fpdf\Fpdf\Fpdf; ---> use Codedge\Fpdf\Fpdf\Code128;
$pdf = new PDF_Code128('L','mm',array(120,114));

What am I missing to implement this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.