Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

How to merge encrypted PDF files ?

Hello,

In a web app I have developed for a client, there is a functionality to store existing PDF files. Some PDF files are encrypted (it is possible to read them without any password, but it is not possible to merge them without the author password).

For the moment, I use a free PDF merger and this library doesn't merge encrypted PDF files.

It seems to be impossible to remove the encryption without knowing the password. I had a look at the SetaSign API and this API doesn't remove the encryption without knowing the password.

Initially my client used the SmallPDF website which was able to merge these encrypted PDF files without knowing the author password.

So it is sure there is a way doing this. But how ?

I have tested quite all free packages without any success with the encrypted PDF files. And the SetaSign API (not free) seems not to authorize doing this without knowning the password. Whereas SmallPDF does it !

Do you have any idea how to solve my problem ?

Thanks a lot ;).

Vincent

0 likes
6 replies
Amaury's avatar

@vincent15000, The solution from Acrobat expert's old article I read once (sorry, I did not retrieve any link) presented as the only one is to print each encrypted PDF as a new PDF and then merge them… Maybe there is a solution with a virtual printer on the server…

1 like
vincent15000's avatar

@Amaury Thank you for your suggestion.

I have also searched for a solution and I contacted SetaSign. They told me that if the author has encrypted his PDF file, nobody can remove the encryption without the authorization of the author.

Their (SetaSign) PDF packages will have the same behavior : no possible merging of encrypted PDF files. But with one of their packages, they can give me a piece of code to remove the encryption only if I onfirm them that my client has the authorization to remove and manipulate the PDF files.

So it's among all a problem of rights.

I will test what you suggest me with a virtual PDF printer, that's effectively a good idea which I didn't thought about at all. I will tell you if it worked or not.

DJAG95's avatar

I have managed to get around this limitation by generating images for each page of the pdf and then converting the images into a PDF using one image per page, but apart from making the generated pdf considerably heavier and losing quality, you lose the ability to search the resulting pdf, could you provide the way or the package used to be able to remove signatures from documents for which you have full rights?

I have used the following function:

use Spatie\PdfToImage\Pdf as PdfImagen;
use Barryvdh\DomPDF\Facade\Pdf;

public function eliminarEncriptadoFirma($ruta)
    {
        $pdf = new PdfImagen($ruta);
        $pdf->setOutputFormat('jpg'); // Puedes cambiar el formato de salida según tus necesidades

        $rutaImagenes = storage_path().'/app/public/';

        $pdf->saveAllPagesAsImages($rutaImagenes);

        $imageFiles = glob($rutaImagenes.'/*.jpg'); // Obtén la lista de imágenes

        // Crea un nuevo PDF
        $pdf = PDF::loadView('pdf.image_pdf', compact('imageFiles'));
    
        // Guarda el PDF en el servidor
        $pdf->save($ruta);
    
        // Elimina las imágenes originales
        foreach ($imageFiles as $imageFile) {
            unlink($imageFile);
        }

    }
1 like
macwojs's avatar

Hi What did you do at the end? Did you resolve this issue? I have a client, and he wants to merge some factures in PDF, but some of them are encrypted. It's factures for him, so he has rights, and we only need to merge multiple of them to print all of them at once.

1 like
vincent15000's avatar

@macwojs It's invoices for him, so it has not the rights to decrypt the PDF files. Only the issuer has the rights, otherwise all recipients could modify the invoices.

Please or to participate in this conversation.