If you have bar code generator extension from yii http://www.yiiframework.com/extension/barcodegenerator/ already doing some configuration on it. Then the next step is to print the image when you access this link http://localhost/sampleapps/barcodegenerator/generatebarcode&code=<?php echo $_IDUSER; ?>
First of all you will have your printing button defined as
$this->widget('zii.widgets.jui.CJuiButton', array(
'buttonType'=>'button',
'name'=>'btnPrint',
'value'=>'1',
'caption'=>'Print',
'onclick'=>'js:function(){
window.location="index.php r=controller/action&barcodeno='.$item->barcodeno.'";
return false;
}',
'htmlOptions'=>array(
'style'=>'color:#28409A;'
),
));
then to that page which you will be going to display your bar code, it will have an image like this
<div id="div1">
<img src="<?php echo Yii::app()->request->baseUrl.'/index.php?r=barcodegenerator/generatebarcode&code='.$item->barcodeno;?>">
</div>
then you will put this code above your div
<script type="text/javascript">
printDivCSS = new String ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">')
window.onload = function printDiv() {
window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById('div1').innerHTML
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()
}
</script>
<iframe name=print_frame width=0 height=0 frameborder=0 src=about:blank></iframe>
if you have more questions please subscribe
$this->widget('zii.widgets.jui.CJuiButton', array(
'buttonType'=>'button',
'name'=>'btnPrint',
'value'=>'1',
'caption'=>'Print',
'onclick'=>'js:function(){
window.location="index.php r=controller/action&barcodeno='.$item->barcodeno.'";
return false;
}',
'htmlOptions'=>array(
'style'=>'color:#28409A;'
),
));
then to that page which you will be going to display your bar code, it will have an image like this
<div id="div1">
<img src="<?php echo Yii::app()->request->baseUrl.'/index.php?r=barcodegenerator/generatebarcode&code='.$item->barcodeno;?>">
</div>
then you will put this code above your div
<script type="text/javascript">
printDivCSS = new String ('<link href="myprintstyle.css" rel="stylesheet" type="text/css">')
window.onload = function printDiv() {
window.frames["print_frame"].document.body.innerHTML=printDivCSS + document.getElementById('div1').innerHTML
window.frames["print_frame"].window.focus()
window.frames["print_frame"].window.print()
}
</script>
<iframe name=print_frame width=0 height=0 frameborder=0 src=about:blank></iframe>
if you have more questions please subscribe
No comments:
Post a Comment