Created
April 29, 2025 09:57
-
-
Save milan-sahana/8fa293cd3a950907e9c90b84116f6be7 to your computer and use it in GitHub Desktop.
Make labels A4 paper (39 x 47.5 mm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$content = <<<EOD | |
<html> | |
<head> | |
<style> | |
@page { | |
margin: 2mm 5mm 0 5mm; | |
padding: 0; | |
size: 210mm 297mm; | |
} | |
/* | |
div { | |
margin: 0; | |
padding: 0; | |
} | |
*/ | |
</style> | |
</head> | |
<body> | |
EOD; | |
for($i1=1;$i1<=6;$i1++) { | |
$margin2 = (($i1+6)%6)?'0 0 2mm 0':'0 !important'; | |
$content .= <<<EOD | |
<div style="padding: 0; margin:0; background-color: red; "> | |
EOD; | |
for($i=1;$i<=5;$i++) { | |
$bg1 = (($i+2)%2)?'blue':'green'; | |
$margin1 = (($i+5)%5)?'0 1mm 0 0':'0 !important'; | |
$width1 = (($i+5)%5)?'40':'39'; | |
$name_text = rand(0, 1) ? 'WWWWWW WWWWWW WWWWWW' : 'WWWWWW WWWWWW'; | |
// background-color: blue; margin: 1mm; padding:0; float: left; width: 39mm; max-height:47.5mm !important; text-align:center; | |
$content .= <<<EOD | |
<div style="background-color: {$bg1}; float:left; width: {$width1}mm; padding:0; margin: 0 0 2mm 0; /* min-height: 49.5mm; */ position: relative; "> | |
<table style="background-color: #0ab39c; width:100%; margin:{$margin1}; border:none; padding: 0; border-spacing: 0px; border: 0; table-layout:fixed; "> | |
<tr style="width:100%; margin:0; padding: 0; border: 0"> | |
<td style="margin:0; border: 0; width:100%; text-align: center; background-color: white; padding: 2mm; height: 27.5mm; overflow: hidden; "> | |
<img src="https://www.drupal.org/files/project-images/googleQRcodes.png" width="22mm"/> | |
</td> | |
</tr> | |
<tr style="border: 0; margin:0; padding: 0;" > | |
<td style="border: 0; margin:0; padding: 0 0 2mm 0; text-align: center; height:20mm; overflow: hidden; width: 40mm; font-size: small;"> | |
{$name_text} | |
<br/> | |
+91-9876543210 | |
<br/> | |
A- 2, C-{$margin1}, I-{$i} | |
</td> | |
</tr> | |
</table> | |
</div> | |
EOD; | |
} | |
$content .= <<<EOD | |
</div> | |
EOD; | |
} | |
$content .= <<<EOD | |
</body> | |
</html> | |
EOD; | |
error_reporting(E_ALL); | |
ini_set("display_errors", 1); | |
//include 'layouts/session.php'; | |
include 'layouts/config.php'; | |
//include (__DIR__."/dbcon/Database.php"); | |
include(__DIR__."/functions/fncEvent.php"); | |
require_once __DIR__.'/../third_party/vendor/autoload.php'; | |
// if(isset($_REQUEST['html'])) { | |
// $content = trim($_REQUEST['html']); | |
$mpdf = new \Mpdf\Mpdf([ | |
'setAutoTopMargin' => 'stretch', | |
/* 'autoMarginPadding' => 5, | |
'format' => 'A4', */ | |
'margin-top' => 0, | |
'margin-header' => 0, | |
'margin-bottom' => 0, | |
'margin-footer' => 0, | |
'mode' => 'utf-8', | |
]); | |
//echo $content; | |
//die; | |
$mpdf->WriteHTML($content); | |
//$mpdf->AddPage(); | |
//$mpdf->WriteHTML('<h1>Hello world 2!</h1>'); | |
// $mpdf->Output(uniqid().'.pdf', 'D'); | |
$mpdf->Output(uniqid().'.pdf', 'I'); | |
// } | |
die; | |
/* | |
?> | |
<html> | |
<body> | |
<form method="post" enctype="multipart/form-data"> | |
<div style=" margin: 0; width: 100%; align-content: center; text-align: center; background-color: red; "> | |
<br/> | |
<textarea name="html" rows="10" placeholder="HTML code" cols="80"> | |
<html> | |
<head> | |
<style> | |
@page { | |
margin: 0; | |
padding: 0; | |
} | |
/* | |
div { | |
margin: 0; | |
padding: 0; | |
} | |
* / | |
</style> | |
</head> | |
<body> | |
<?php | |
for($i=0;$i<2;$i++) { | |
?> | |
<div style="margin-left: 3mm; margin-right: 3mm; margin-top: 2mm; background-color: red; "> | |
<?php | |
for($i=0;$i<30;$i++) { | |
?> | |
<div style=" background-color: blue; margin: 1mm; padding:0; float: left; width: 39mm; max-height:47.5mm !important; text-align:center; "> | |
<img src="https://www.drupal.org/files/project-images/googleQRcodes.png" width="25mm"/> | |
<br/> | |
<span style="overflow: hidden; margin: 0;"> | |
Milan Sahana, 9876543210, A- 2, C-6, I-6 | |
</span> | |
</div> | |
<?php | |
} | |
?> | |
</div> | |
<?php | |
} | |
?> | |
</body> | |
</html> | |
</textarea> | |
<br/> | |
<br/> | |
<button type="submit">Submit</button> | |
</div> | |
<?php /* ?> | |
<style> | |
span { | |
width: 30mm; | |
height: 47mm; | |
margin: auto; | |
border: 1px solid red; | |
display: inline-flex; | |
} | |
</style> | |
<span> | |
<img src="https://www.drupal.org/files/project-images/googleQRcodes.png" width="25mm"/> | |
WWWWWW | |
</span> | |
<span> | |
<img src="https://www.drupal.org/files/project-images/googleQRcodes.png" width="25mm"/>WWWWWWWW | |
</span> | |
<div style="clear: both; margin: 0pt; padding: 0pt; "></div> | |
This is text that follows the clear:both. | |
</div> | |
<?php * / ?> | |
</form> | |
</body> | |
</html> | |
<?php | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment