Giter Site home page Giter Site logo

Duplicated attachment about tcpdf HOT 2 OPEN

wangshy avatar wangshy commented on May 13, 2024
Duplicated attachment

from tcpdf.

Comments (2)

nivv avatar nivv commented on May 13, 2024 1

#236 was closed, not sure why. But you can still use this functinality if you extend the original Fpdi class. Below is an example:

<?php

namespace App\Services;

use setasign\Fpdi\Tcpdf\Fpdi;
use TCPDF_STATIC;

class RFPDI extends Fpdi
{
        public function createPDF() {
             $attachment = storage_path('/app/logos/0Zs80Mh5mhfc7g213Ui33qov8X9gXyhKDCSLOvmG.png');
             $this->Attachment($attachment);
        }

        public function Attachment($filestream) {
		if (!$this->pdfa_mode || ($this->pdfa_mode && $this->pdfa_version == 3)) {
			if ((!TCPDF_STATIC::empty_string($filestream))
				AND (@TCPDF_STATIC::file_exists($filestream) OR TCPDF_STATIC::isValidURL($filestream))
				AND (!isset($this->embeddedfiles[basename($filestream)]))) {
				$this->embeddedfiles[basename($filestream)] = array('f' => ++$this->n, 'n' => ++$this->n, 'file' => $filestream);
			}
		}
	}
}

from tcpdf.

ddonkersgoed-echidna avatar ddonkersgoed-echidna commented on May 13, 2024

I looked into this a bit (I work with wangshy at Digital Echidna) and I think the issue we were having was that we assumed an attachment had to be added as a PDF annotation (and this seems to be the only way to do it in TCPDF). However, adding the attachment and the annotation are actually two separate steps and you can have an attachment without an annotation.

I'm not sure this is strictly speaking a bug (possibly Acrobat Reader just always displays duplicates when there's an attachment referenced in an annotation and this therefore isn't a problem in tcpdf?) but since we were using the attachments tab to reference the connected files and not actually using the annotation (it was just stuck in the corner of the file barely noticeable) the easiest workaround is to just do the attachment without the annotation.

I've opened a PR here that adds a method for that: #236

It can be used like so:

$this->tcpdf->Attachment($attachment);

from tcpdf.

Related Issues (20)

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.