Closed Maxtab closed 1 year ago
OK I managed to resolve this bug which does not seem to be linked to FPDI but rather FPDF. My function uses a rotation function which was constructed like this:
use setasign\Fpdi\Fpdi;
class PdfRotate extends Fpdi
{
// Variable pour stocker l'angle de rotation
private $angle = 0;
public function rotate(float $angle, ?float $x = null, ?float $y = null): void
{
$x = $x ?? $this->x;
$y = $y ?? $this->y;
if ($this->angle !== 0) {
$this->_out('Q');
}
$this->angle = $angle;
if ($angle !== 0) {
$angleRad = deg2rad($angle);
$c = cos($angleRad);
$s = sin($angleRad);
$cx = $x * $this->k;
$cy = ($this->h - $y) * $this->k;
$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
}
}
protected function endPage(): void
{
if ($this->angle !== 0) {
$this->angle = 0;
$this->_out('Q');
}
parent::_endpage();
}
}
After using the code found on the FPDF site (FPDF doc about Rotations), which is this:
use setasign\Fpdi\Fpdi;
class PdfRotate extends Fpdi
{
var $angle=0;
function Rotate($angle,$x=-1,$y=-1)
{
if($x==-1)
$x=$this->x;
if($y==-1)
$y=$this->y;
if($this->angle!=0)
$this->_out('Q');
$this->angle=$angle;
if($angle!=0)
{
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->k;
$cy=($this->h-$y)*$this->k;
$this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
}
}
function _endpage()
{
if($this->angle!=0)
{
$this->angle=0;
$this->_out('Q');
}
parent::_endpage();
}
}
I no longer encounter this bug at all. I didn't quite understand what changed the result, but it works. I'll leave this here if anyone has the same problem.
Hello and thank you for your tool which is very useful.
I notice a bug but I'm not sure if it concerns FPDI or Acrobat.
I'm generating some edits to an existing PDF using the following script which adds text to each page of a PDF.
By retrieving the transformed PDF, when I view it in a browser, I can clearly see the text on each page which has been added as expected. But on Acrobat (or even on Default document viewer on Ubuntu), I only see the text added on the first page and not the following ones, it's quite strange. Has anyone ever noticed this? Does this have anything to do with how the PDF is saved?
Versions used :
Example of file generated with this script : packing_slip_2572251_bis_HIOLLE_HIOLLE (1).pdf
There should be text similar to what is seen on the first page on each of the 7 pages. If you view this PDF in you browser such as Chrome or Firefow, you will see the text fine on the 7 pages, but on Acrobat or default Document viewer as I said, it does not display except for the first page (and does not print either)
Thank you for your help.