Skip to content

Invalid label PDF file in Firefox, not in Chrome #535

Description

@jelledruut

SDK version

9.0.0

PHP version

8.3

What went wrong?

We're using Firefox for our internal shipping application, but it can't seem to open PostNL MyParcel PDF files, due to an Invalid stream error.

It happens both with downloadPdfOfLabels and manually saving the contents from getLabelPdf (downloadPdfOfLabels also uses label_pdf though)

The thing is, the PDF's are displayed just fine in Chrome, but not in Firefox. We're storing/printing/opening a variety of labels from different sources, but I haven't experienced this issue before.

Warning: Invalid stream: "FormatError: Unknown compression method in flate stream: 50, 32" [pdf.worker.mjs:323:13](resource://pdf.js/build/pdf.worker.mjs)
        // Please fill in those variables
        $person = ''; 
        $street = '';
        $number = '';
        $numberAdditional = '';
        $postalCode = '';
        $city = '';
        $countryCode = 'NL';

        $consignment = (\MyParcelNL\Sdk\Factory\ConsignmentFactory::createByCarrierName('postnl'))
            ->setApiKey(config('services.my_parcel.api_key'))
            ->setCountry($countryCode)
            ->setPerson($person)
            ->setStreet($street)
            ->setNumber($number)
            ->setStreetAdditionalInfo($numberAdditional)
            ->setPostalCode($postalCode)
            ->setCity($city);

        $consignments = (new \MyParcelNL\Sdk\Helper\MyParcelCollection())
            ->addConsignment($consignment)
            ->setPdfOfLabels(false); // A6

        $consignments->downloadPdfOfLabels();

Part of our actual code:

        $consignment = (ConsignmentFactory::createByCarrierName('postnl'))
            ->setApiKey(config('services.my_parcel.api_key'))
            ->setCountry($address->countryCode)
            ->setPerson($address->getFullName())
            ->setStreet($address->street)
            ->setNumber($address->number)
            ->setPostalCode($address->postalCode)
            ->setCity($address->city);

        // other code

        $consignments = (new MyParcelCollection())
            ->addConsignment($consignment)
            ->setPdfOfLabels(false); // A6

        /** @var AbstractConsignment $consignment */
        $consignment = $consignments->first();

        $trackingId = $consignment->getBarcode();
        $trackingUrl = $consignment->getBarcodeUrl(
            barcode: $trackingId,
            postalCode: $address->postalCode,
            countryCode: $address->countryCode,
        );

        return new ShippingLabel(
            trackingId: $trackingId,
            trackingUrl: $trackingUrl,
            pdfContents: $consignments->getLabelPdf(),
        );

Reproduction steps

  1. Create a 'postnl' label through the code provided
  2. Store the contents to a PDF file (e.g. file_put_contents('file.pdf', $consignments->getLabelPdf());
    2.1. Alternatively, use downloadPdfOfLabels for the same result
  3. Open the PDF in Firefox
  4. Firefox displays a blank PDF and throws an error in the dev tools console

Relevant log output

Additional context

Image

We're using the most recent stable version of Firefox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions