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

AzharAbbas's avatar

Dymo LabelWriter 450 with Laravel

I want to print label from my website direct for this purpose I'm using dymo Label framework sdk but it is giving me following error GET https://localhost:41951/DYMO/DLS/Printing/StatusConnected net::ERR_CONNECTION_CLOSED when I see in network tab in show following message CORS policy: No 'Access-Control-Allow-Origin'

0 likes
4 replies
Tray2's avatar

That means that you are trying to access the url from a server that is not allowed, ajax calls are usually not allowed from localhost. So set up a domain from which you load your application and then make sure the labelwriter allows that domain.

AzharAbbas's avatar

@Tray2 I have live this project on namecheap but when I click on print button it give me this error Request URL: https://localhost:41960/DYMO/DLS/Printing/StatusConnected Referrer Policy: strict-origin-when-cross-origin

following is my code async function printLabel() { try { // Initialize the DYMO Web Service await dymo.label.framework.init(); console.log('DYMO Web Service is running'); loadLabel(); } catch (err) { console.error('Error initializing DYMO Label Framework:', err); } }

    function loadLabel() {
        // Define the label XML content
        const labelXml = `
            <DieCutLabel Version="8.0" Units="twips">
                <PaperOrientation>Landscape</PaperOrientation>
                <Id>Small30347</Id>
                <IsOutlined>false</IsOutlined>
                <PaperName>30347 Shipping</PaperName>
                <DrawCommands/>
                <ObjectInfo>
                    <TextObject>
                        <Name>Text</Name>
                        <ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
                        <BackColor Alpha="0" Red="255" Green="255" Blue="255"/>
                        <LinkedObjectName></LinkedObjectName>
                        <Rotation>Rotation0</Rotation>
                        <IsMirrored>False</IsMirrored>
                        <IsVariable>True</IsVariable>
                        <HorizontalAlignment>Left</HorizontalAlignment>
                        <VerticalAlignment>Middle</VerticalAlignment>
                        <TextFitMode>AlwaysFit</TextFitMode>
                        <UseFullFontHeight>True</UseFullFontHeight>
                        <Verticalized>False</Verticalized>
                        <StyledText>
                            <Element>
                                <String>Order ID: 123456\nClient ID: 78910\nOrder Date: 2024-06-27\nFault: None\nPIN: 1234\nAuth Reset: Yes\nhttps://example.com</String>
                                <Attributes>
                                    <Font Family="Arial" Size="10" Bold="True" Italic="False" Underline="False" Strikeout="False"/>
                                    <ForeColor Alpha="255" Red="0" Green="0" Blue="0"/>
                                </Attributes>
                            </Element>
                        </StyledText>
                    </TextObject>
                    <Bounds X="0" Y="0" Width="2000" Height="1000"/>
                </ObjectInfo>
            </DieCutLabel>
        `;

        // Load the label content into a DYMO label object
        const label = dymo.label.framework.openLabelXml(labelXml);

        // Select the printer
        const printers = dymo.label.framework.getPrinters();
        if (printers.length === 0) {
            console.error('No DYMO printers found');
            return;
        }

        const printerName = "DYMO LabelWriter 450"; // Replace with your DYMO printer name
        const printer = printers.find(printer => printer.name === printerName);

        if (!printer) {
            console.error(`Printer "${printerName}" not found`);
            return;
        }

        // Print the label
        label.print(printerName);
        console.log('Print job sent successfully');
    }
</script>
Tray2's avatar

@AzharAbbas Is the printer software installed on the server, and the printer connected to it, or is the printer connected to you local computer? The web server needs to be able to connect to the printer.

Please or to participate in this conversation.