Coder Social home page Coder Social logo

fawno / fpdf Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 4.0 674 KB

FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.

Home Page: http://www.fpdf.org/

License: MIT License

PHP 60.30% HTML 39.35% CSS 0.35%
fpdf pdf pdf-generation php-library

fpdf's People

Contributors

alphp avatar angeljqv avatar erikn69 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fpdf's Issues

What should be done for version 1.84.2?

In dev-master new features and scripts are being introduced, but the tags allow to define a stable point of the code.

composer require fawno/fpdf:@stable

What should be done for the 1.84.2 tag?

  • Documentation
  • Check the content of the pdf created in the tests
  • Must-have scripts
  • Other features

The essential documentation is almost complete, missing some pages that I would like to have to release the 1.84.2 tag.

FPDF Protection Script

http://www.fpdf.org/en/script/script37.php

FPDF Protection Script prevent people from copying its content, print it or modify it.

SetProtection([array permissions [, string user_pass [, string owner_pass]]])

permissions: the set of permissions. Empty by default (only viewing is allowed).
user_pass: user password. Empty by default.
owner_pass: owner password. If not specified, a random value is used.

FPDF Memory Image Support

http://www.fpdf.org/en/script/script45.php

Description
This script allows to display images that are loaded in memory without the need of temporary files. There are three main uses:

  • When an image is loaded from a database
  • When an image is created with GD
  • When an image is created with any image generator on the fly

For an image loaded into a string:

MemImage(string data [, float x [, float y [, float w [, float h [, mixed link]]]]])

For a GD image:

GDImage(resource im [, float x [, float y [, float w [, float h [, mixed link]]]]])

where im is the GD identifier.

Example:

$pdf = new PDF_MemImage();
$pdf->AddPage();

// Load an image into a variable
$logo = file_get_contents('logo.jpg');
// Output it
$pdf->MemImage($logo, 50, 30);

// Create a GD graphics
$im = imagecreate(200, 150);
$bgcolor = imagecolorallocate($im, 255, 255, 255);
$bordercolor = imagecolorallocate($im, 0, 0, 0);
$color1 = imagecolorallocate($im, 255, 0, 0);
$color2 = imagecolorallocate($im, 0, 255, 0);
$color3 = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 0, 0, 199, 149, $bgcolor);
imagerectangle($im, 0, 0, 199, 149, $bordercolor);
imagefilledrectangle($im, 30, 100, 60, 148, $color1);
imagefilledrectangle($im, 80, 80, 110, 148, $color2);
imagefilledrectangle($im, 130, 40, 160, 148, $color3);
// Output it
$pdf->GDImage($im, 120, 25, 40);
imagedestroy($im);

$pdf->Output();

Support Closure Macros for common tasks

It could be really helpful

Examples:
https://github.com/spatie/macroable/blob/main/src/Macroable.php
https://github.com/illuminate/macroable/blob/master/Traits/Macroable.php
mike42/escpos-php@dd16a6d

Code:

declare(strict_types=1);

use BadMethodCallException;
use Closure;

namespace FPDF\Scripts\PDFMacroable;

trait PDFMacroableTrait {
    /**
     * The registered string macros.
     *
     * @var array
     */
    protected static $macros = [];

    /**
     * Register a custom macro.
     *
     * @param  string  $name
     * @param  callable  $macro
     * @return void
     */
    public static function macro($name, $macro)
    {
        static::$macros[$name] = $macro;
    }

    /**
     * Dynamically handle calls to the class.
     *
     * @param  string  $method
     * @param  array  $parameters
     * @return mixed
     *
     * @throws \BadMethodCallException
     */
    public function __call($method, $parameters)
    {
        if (! isset(static::$macros[$name])) {
            throw new BadMethodCallException(sprintf(
                'Method %s::%s does not exist.', static::class, $method
            ));
        }

        $macro = static::$macros[$method];

        if ($macro instanceof Closure) {
            $macro = $macro->bindTo($this, static::class);
        }

        return $macro(...$parameters);
    }
}

So we can add custom scripts to the class, example

FawnoFPDF::macro('SetDash', function($black=null, $white=null) {
    if($black!==null)
        $s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k);
    else
        $s='[] 0 d';
    $this->_out($s);
});
$pdf=new PDF_Dash();
$pdf->AddPage();
$pdf->SetLineWidth(0.1);
$pdf->SetDash(5,5); //5mm on, 5mm off
$pdf->Line(20,20,190,20);
$pdf->SetLineWidth(0.5);
$pdf->Line(20,25,190,25);
$pdf->SetLineWidth(0.8);
$pdf->SetDash(4,2); //4mm on, 2mm off
$pdf->Rect(20,30,170,20);
$pdf->SetDash(); //restores no dash
$pdf->Line(20,55,190,55);
$pdf->Output();

Result Here

image

Table with MultiCells Trait Missing

http://www.fpdf.org/en/script/script3.php

Description:
The goal of this script is to show how to build a table from MultiCells.
As MultiCells go to the next line after being output, the base idea consists in saving the current position, printing the MultiCell and resetting the position to its right.
There is a difficulty, however, if the table is too long: page breaks. Before outputting a row, it is necessary to know whether it will cause a break or not. If it does overflow, a manual page break must be done first.
To do so, the height of the row must be known in advance; it is the maximum of the heights of the MultiCells it is made up of. To know the height of a MultiCell, the NbLines() method is used: it returns the number of lines a MultiCell will occupy.

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.