Распечатать PDF с таблицей со штрих-кодом в codeigniter - PullRequest
0 голосов
/ 05 апреля 2019

Я пытаюсь напечатать таблицу в формате pdf, где 1 столбец является штрих-кодом. Я могу установить штрих-код в списке, но не в PDF.

Из того, что я искал, у меня есть 2 метода TCPDF, установленных в контроллере, или js ajax, установленных в поле зрения. В этот момент я попробовал оба, но не смог установить правильный код для вывода pdf, как я хочу.

метод 1 TCPDF в контроллере. В связи с этим у меня есть кнопка, которая указывает на контроллер для отображения данных, где id_cod_obra =? это вид это сгенерированный PDF, но без печати штрих-кода

 function createPDF(){





        if ($this->session->userdata('logged_in')) { // VALIDA USU�RIO LOGADO
            $this->load->model('model_perfil');
            $resultadoPerfil = $this->model_perfil->buscaPerfil();
            $dados ['resultadoPerfil'] = $resultadoPerfil;
            $this->load->model('htmltopdf_model');
            $this->load->library('pdf');


            /////////////////////////////////////


    $this->load->library('Pdf');


    // $this->pdf->setPaper('A4', 'landscape');
      $this->pdf->setPaper('A4', 'portrait');


            ////////////////////////////////////////

            $id_cod_obra = $this->input->get('id_cod_obra');
            //   $id = $this->uri->segment(2);
            $html_content= $this->htmltopdf_model->carregapecasfiltro($id_cod_obra);
            //$html_content ['html_content'] = $html_content;
            $html_content = '<h3 align="center">Convert HTML to PDF in CodeIgniter using Dompdf MERDA ISTO ESTA A DEMORAR 2</h3>';



    $template = array('table_open' => '<table border="1" cellpadding="2" cellspacing="1">');

    $this->table->set_template($template);

    $this->table->set_heading('ID peça', 'ID obra', 'nome ', 'Nr Subcj', 'mb ', 'ma ', 'Codigo Barrras ');

     $this->load->model('model_peca');


     // CODE 128 A
//$pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
//$pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
//$pdf->Ln();

//$params = $pdf->serializeTCPDFtagParameters(array('CODE 128', 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
//$html .= '<tcpdf method="write1DBarcode" params="'.$sf->codigoean.'" />';

    $html_content= $this->htmltopdf_model->carregapecasfiltro($id_cod_obra);
     $dados ['html_content'] = $html_content;

            foreach($html_content as $s){

        //  $codigoean=['codigoean'];

            //$codigoean=$row['codigoean'];
        //  $codigoean = $pdf->serializeTCPDFtagParameters(array($codigoean, 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
//



                                            ;}
//$codigoean = $pdf->serializeTCPDFtagParameters(array($codigoean, 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));



                            //      var_dump( $this->table->add_row($s->codigoean()) );
                            //      die;


    // $html .= '<tcpdf method="write1DBarcode" params="'.$sf->codigoean.'" />'
    //$html .= '<tcpdf method="write1DBarcode" params="' . $params . '" />';
    //$codigoean = $pdf->serializeTCPDFtagParameters(array('CODE 128C+', 'C128C', '', '', 80, 30, 0.4, array('position' => 'S', 'border' => true, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => true, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N'));

    foreach ($html_content as $sf):

        $this->table->add_row($sf->id, $sf->id_cod_obra, $sf->nome , $sf->qtd, $sf->nr_de_peca, $sf->ma, $barcode );
    //  
        // $this->table->add_row($sf->codigoean );

    endforeach;
    $html_content = $this->table->generate();




   $this->pdf->loadHtml($html_content);
   $this->pdf->render();
   $this->pdf->stream("".$id_cod_obra.".pdf", array("Attachment"=>1));
   //  $this->pdf->stream('my.pdf', array("Attachment"=>0));
  // $dompdf->stream('my.pdf',array('Attachment'=>0));




     }}

Это дата, но не может поставить штрих-коды внутри таблицы 2 метода с AJAX JS




      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>
  <script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
 <script src="<?php echo site_url('assets/JsBarcode-3.11.0/dist/JsBarcode.all.js'); ?>"></script>
   <script>
    function textToBase64Barcode(text){
      var canvas = document.createElement("canvas");
      JsBarcode(canvas, text, {format: "CODE39"});
      return canvas.toDataURL("image/png");
    }
  </script>


<div class="content-wrapper">
    <section class="content-header">

        <section class="content-header">
        <h1>
            Requisi&ccedil;&atilde;o AJAX
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Requisiçao AJAX</li>
        </ol>
    </section>




 <div class="box">

  <html lang="en">
      <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">







      </head>


      <body style="background: #c9c3c3">

        <div class="container">
            <div class="table justify-content-center">




////////////JUST TO TEST IF BARCODE RENDER IN VIEW "TEST"///////

        <svg id="example2"></svg>
          <a id="hello">Click Here</a>






                <div class="col-10 mb-5">
                   <div class="card mt-3">
                       <div class="card-body">



                           <h5 class="card-title text-center">---------------------------</h5>


                              <div class="table-responsive">




    <table id="example" class="table  table-bordered table-striped">
     <thead>  
       <tr>  
        <th>#</th>  
         <th>id</th>  
         <th>obra</th>  
         <th>nome</th>  
         <th>qtd</th>  
         <th>data</th>  
         <th>Nr CJ</th>  
         <th>NR Peça</th>  
         <th>Prep</th>
         <th>Doc</th>
         <th>Tipo</th>
         <th>Desc.</th>
         <th>CB</th>
         <th>area</th>
         <th>peso</th>
         <th>Kg MA</th>
         <th>status</th>

       </tr>  
     </thead>  
     <tfoot>  

        <tr>  

       </tr>  
     </tfoot>  
     <tbody>  
       <tr>  
                     <?php if(!empty($peca)): ?>
                                <?php foreach($peca as $pecas):                                 
                                ?>
                                <tr>
                                    <th><?= $pecas->id?></th>
                                    <th><?= $pecas->id_cod_obra?></th>
                                    <th><?= $pecas->nome?></th>
                                    <th><?= $pecas->qtd?></th>
                                    <th><?= $pecas->data_entrada?></th>
                                    <th><?= $pecas->nr_subconjunto?></th>
                                    <th><?= $pecas->nr_de_peca?></th>
                                    <th><?= $pecas->preparou?></th>
                                    <th><?= $pecas->doc_anexo?></th>
                                    <th><?= $pecas->tipo_doc?></th>
                                    <th><?= $pecas->descricao?></th>

                                    <!--            <th></th> -->


                                    <!--    <th><?//=   $pecas->codigoean?></th>

                                    <td><?php// echo $pecas->codigoean;?><svg id="hello"></svg></td>


                        </th>
                                    <img src="<?php //echo base_url('Barcode/barcode_generator')?>/code128a/15/ ?> <th><?//= $pecas->codigo_barras ?> </th> ;?>/true"/>
                                    </th>


                            <td> 

                                            <img src="<?php// echo base_url('Barcode/barcode_generator')?>/code128a/15/<?php//  echo// $pecas->codigoean  ;?>/true"/>





                                                                        </td>-->



                                    <th><?= $pecas->area?></th>
                                    <th><?= $pecas->peso?></th>
                                    <th><?= $pecas->kg_solda?></th>
                                    <th><?= $pecas->status?></th>




                                </tr>
                                <?php endforeach ;?>
                            <?php endif;?>
       </tr>  
       <tr>  

     </tbody>  
   </table> 
                       </div>
                   </div>
                </div>
            </div>
        </div>


      </body>
    </html>

            </div>

        </div>



    </section>
</div>





 <script src="<?php echo site_url('assets/JsBarcode-3.11.0/dist/JsBarcode.all.js'); ?>"></script>



<script type="text/javascript" language="javascript" >




  $(document).ready(function(){

  $('#example').DataTable({
      // Processing indicator
   "processing" : true,
   // DataTables server-side processing mode
   "serverSide" : true,
           // Initial no order.
    "order": [],
    // Load data from an Ajax source
   "ajax" : {
     "url": "getLists",
    type:"POST"
   },
   dom: 'lBfrtip',
   buttons: [
    'excel', 'csv', 'pdf', 'copy'
   ],
   "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
        "aaSorting": [[0, 'desc']],
        "aoColumnDefs": [
            {"sType": "num-html", "aTargets": [0]}

        ],


  });


 });

  $("#example2").JsBarcode("TEST");

  document.querySelector("#hello").href = textToBase64Barcode("HELLO");




</script>

В 1 TCPDF я печатаю таблицу со штрих-кодом в цифрах. В 1 я также могу вставить в поле вид столбца штрих-кода с этим кодом

<img src="<?php echo base_url('Barcode/barcode_generator')?>/code128a/15/<?php  echo $pecas->codigoean  ;?>/true"/>

В 2 AJAX JS я печатаю таблицу со штрих-кодом в цифрах. И все работы превосходят / pdf / copy

JSBarcode только для проверки выводит правильно штрих код, который я поставил для "ТЕСТ"

Ответы [ 3 ]

0 голосов
/ 05 апреля 2019

просто используйте этот, у меня это сработало.

$obj_pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
$obj_pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');

ссылка: Пример TCPDF

0 голосов
/ 08 апреля 2019

так выглядит печать Это позволит печатать изображения со штрих-кодом, а не решение, которое я искал, но, по крайней мере, оно работает

      <link href="assets/impecran/style.css" media="screen" rel="stylesheet" type="text/css" />
      <script language="javascript">
        function Clickheretoprint()
        { 
          var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
              disp_setting+="scrollbars=yes,width=1000, height=500, left=100, top=25"; 
          var content_vlue = document.getElementById("tablecon").innerHTML; 

          var docprint=window.open("","",disp_setting); 
           docprint.document.open(); 
           docprint.document.write('</head><body onLoad="self.print()" style="width: 1000px; font-size:11px; font-family:arial; font-weight:normal;">');          
           docprint.document.write(content_vlue); 
           docprint.document.close(); 
           docprint.focus(); 
        }
        </script>

      <section class="content">
            <div class="row">
                  <div class="col-xs-12 col-sm-12 col-lg-12">
                        <div class="box box-warning">




                              <?php
                              if (isset($msg)) {
                                    echo '<div class="box-header with-border">' . $msg . '</div>';


                              }
                    //    echo anchor('Home/createPDF', 'Generate PDF Report');



                              ?>



                                  <?php
                                                      if ((isset($resultadoPeca)) && (!empty($resultadoPeca))) {
                                                      foreach ($resultadoPeca as $pecas) {  $pecas->id_cod_obra;}} //vai retornar o id_cod_obra n vezes igual por isso escolho o ultimo da lista
                                                                  ?>                                                          

                                                                  <a href="createPDF?id_cod_obra=<?php echo $pecas->id_cod_obra;  ?>" class="btn btn-default"><i  class="fa fa-plus"></i> PDF</a>
                                                          <?php        ?>
                                                            <tr>


                              <div class="box">
<!--                                    <div class="box-header with-border">
                                          <h3 class="box-title">Lista de pecas</h3>
                                    </div>-->
                                    <!-- /.box-header -->




                                    <div class="box-body">
                                          <form role="form" name="formulariopeca" id="formulariopeca" action="alterapeca" method="post" class="form-horizontal">
                                                <input name="idpeca" id="idpeca" type="hidden" value="" readonly="readonly">
                                          </form>

                                          <span id="title">Products Inventory</span><a id="addd" href="javascript:Clickheretoprint()">Print</a>
                                          <div id="tablecon">
                                       <table id="example1" class="table table-bordered table-striped">
                                                <thead>
                                                      <tr>

                                                            <th>id_cod_obra</th>
                                                            <th>nome</th>
                                                            <th>qtd</th>

                                                            <th>nr_subconjunto</th>
                                                            <th>nr_de_peca</th>


                                                            <th>descricao</th>

                                                            <th>codigoean</th>
                                                            <th>Status</th>
                                                            <th style="width:1px;">&nbsp;</th>

                                                      </tr>
                                                </thead>
                                                <tbody>

                                  <?php
                                                      if ((isset($resultadoPeca)) && (!empty($resultadoPeca))) {
                                                            foreach ($resultadoPeca as $pecas) {
                                                                  ?>                                                          



                                                                  <tr>


                                                                         <td><?php echo $pecas->id_cod_obra; ?></td>
                                                                        <td><?php echo $pecas->nome; ?></td>
                                                                        <td><?php echo $pecas->qtd; ?></td>

                                                                        <td><?php echo $pecas->nr_subconjunto; ?></td>
                                                                        <td><?php echo $pecas->nr_de_peca; ?></td>


                                                                        <td><?php echo $pecas->descricao; ?></td>

.........
0 голосов
/ 05 апреля 2019

Вы должны использовать серверный генератор штрих-кода для работы с потоковым файлом, например, для создания PDF.Я рекомендую использовать этот php-barcode-generator

...