1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Generating PDF/A-3A with mPDF Library in PHP

Discussão em 'Outras Linguagens' iniciado por KL Codes, Outubro 5, 2024 às 07:43.

  1. KL Codes

    KL Codes Guest

    I’m trying to generate a PDF/A-3A document using the mPDF library in PHP, but I keep getting a PDF/A-1B output instead. Here’s the code I’m using:

    <?php
    require_once __DIR__ . '/autoload.php';

    $mpdf = new \Mpdf\Mpdf([
    'mode' => 'utf-8',
    'format' => 'A4',
    'orientation' => 'P',
    'margin_left' => 4,
    'margin_right' => 4,
    'margin_top' => 42,
    'margin_bottom' => 20,
    'margin_header' => 32,
    'margin_footer' => 17,
    'default_font' => 'Myriad Pro',
    'default_font_size' => 8,
    ]);

    $mpdf->SetDefaultBodyCSS('background', "url('./backgroundimage.jpeg')");
    $mpdf->SetDefaultBodyCSS('background-image-resize', 6);

    $mpdf->autoScriptToLang = true;
    $mpdf->autoLangToFont = true;
    $mpdf->SetHTMLHeaderByName('Header');
    // Decode the XML content from base64
    $xmlDecodedContent = base64_decode($xmlEncodeValue);

    // Sanitize $invoiceNo to avoid issues with special characters
    $sanitizedInvoiceNo = preg_replace('/[^\w-]/', '_', $invoiceNo);
    $customTempDir = 'pdf_attachments';
    // Ensure directory exists
    if (!file_exists($customTempDir)) {
    mkdir($customTempDir, 0777, true); // Create directory if it doesn't exist
    }

    // Create a temporary file path for the XML (stored in the system's temporary directory)
    $xmlTempFilePath = $customTempDir . '/invoice_' . $sanitizedInvoiceNo . '.xml';

    // Save the XML content to the temporary file
    file_put_contents($xmlTempFilePath, $xmlDecodedContent);

    // Embed the temporary XML file into the PDF
    $mpdf->SetAssociatedFiles([[
    'name' => 'invoice_' . $sanitizedInvoiceNo . '.xml', // The name that will be shown in the PDF
    'mime' => 'text/xml', // MIME type
    'description' => 'Invoice XML file', // File description
    'AFRelationship' => 'Data', // Relationship to the PDF
    'content' => $xmlDecodedContent // Content of the XML file
    ]]);
    $rdf = '<rdf:Description rdf:about="" xmlns:zf="urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#">'."\n";
    $rdf .= ' <zf:DocumentType>INVOICE</zf:DocumentType>'."\n";
    $rdf .= ' <zf:DocumentFileName>ZUGFeRD-invoice.xml</zf:DocumentFileName>'."\n";
    $rdf .= ' <zf:Version>1.0</zf:Version>'."\n";
    $rdf .= ' <zf:ConformanceLevel>BASIC</zf:ConformanceLevel>'."\n";
    $rdf .= '</rdf:Description>'."\n";

    $mpdf->SetAdditionalXmpRdf($rdf);

    if (file_exists($xmlTempFilePath))
    {
    unlink($xmlTempFilePath); // Delete the temp file
    }
    $mpdf->WriteHTML( $htmlContent);
    $mpdf->SetHTMLFooterByName('Footer');


    ob_clean();
    $mpdf->Output('invoice_' . $sanitizedInvoiceNo . '.pdf', 'I');



    Current Output: Standard: PDF/A-1B ISO Name: ISO 19005-1 Status: not yet verified Output Intent Identifier: sRGB IEC61966-2.1 Info: sRGB IEC61966-2.1

    Desired Output: Standard: PDF/A-3A ISO Name: ISO 19005-3 Status: not yet verified Output Intent Identifier: Custom Info: sRGB IEC61966-2.1

    Question: What adjustments do I need to make to my code to ensure that the generated PDF adheres to the PDF/A-3A standard instead of PDF/A-1B? Any guidance or suggestions would be greatly appreciated!

    What adjustments do I need to make to my code to ensure that the generated PDF adheres to the PDF/A-3A standard instead of PDF/A-1B? Any guidance or suggestions would be greatly appreciated!

    Continue reading...

Compartilhe esta Página