Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can custom paper size define in px #1020

Open
benjirsoft opened this issue Dec 18, 2023 · 1 comment
Open

how can custom paper size define in px #1020

benjirsoft opened this issue Dec 18, 2023 · 1 comment

Comments

@benjirsoft
Copy link

This is First time i use dompdf in my laravel project my custom paper size is 1.5inc/4cm. but i can not do it properly. my code is $html = '<style type="text/css">
.label {
width: 152px;
height: 95px;
font-size: 12pt;
font-family: Sans-serif;
text-align: center;
margin: 0px;
}

    .test {
        margin-bottom: 1px;
        text-align: center;
        transform: rotate(-90deg);
    }

    .barcode {
        display: block;
        margin-top: 3px;
        transform: rotate(-90deg);
        text-align: center;
    }
</style>';

// Loop through the quantity and generate barcode labels
for ($i = 1; $i <= $quantity; $i++) {
    // ... (your existing code for label generation)
    $barcode = $request->input('barcode');
    $product = $request->input('productid');
    $productname = Productinfo::where('productid', $product)->first()->productname ?? null;
    $cprice = $request->input('cprice');

    // Generate the barcode SVG and convert it to PNG
    $barcode_svg = DNS1D::getBarcodeSVG($barcode, 'C128', 1.0, 40);
    $barcode_png = base64_encode($barcode_svg);
    $barcode_src = 'data:image/png;base64,' . $barcode_png;

    $labelHtml = '<div class="label">
        <div class="test">
            <div style="margin-top: 0px; font-size: 9pt; font-weight: bold; font-family:Fjalla; margin-bottom: 1px">
                '.substr($productname, -17).'
                <span style="font-size:10pt; padding:5px">Price: '.$cprice.' Tk</span>
                <div class="barcode">    
                    <img src="'.$barcode_src.'">
                </div>
            </div>
        </div>';
    $html .= $labelHtml;
}

$html .= '</div>';

// Create a new Dompdf instance
$pdf = new Dompdf();

$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isPhpEnabled', true);
$options->set('width', '1.5in'); // Set the width in inches
$options->set('height', '4cm'); // Set the height in centimeters
$pdf->setOptions($options);

// Set the PDF content and options
$pdf->loadHtml($html);
$pdf->setPaper('custom', 'portrait');
$pdf->render();
$pdf->stream('document.pdf', array('Attachment' => 0));  
@parallels999
Copy link

**This is just a Dompdf wrapper!**
I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf
Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

This is just a Dompdf wrapper!
I understand that this package is just a Laravel wrapper for https://github.com/dompdf/dompdf
Any issues with PDF rendering, CSS that is not applied correctly, aligning/fonts/characters/images/html etc that are not directly related to this package, should be reported there. When having doubts, please try to reproduce the issue with just dompdf. If it's also present there, do not open an issue here please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants