Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Mudar tamanho do PDF gerado Bom dia prezados(as), Gostaria de saber se é possível alterar o tamanho do PDF gerado. O pdf é gerado em uma folha A4, gostaria alterar para 5.4 x 8.5, e se possível, e poderem me auxiliar nesse processo ficaria muito grato. ...
PA
Mudar tamanho do PDF gerado  
Bom dia prezados(as),
Gostaria de saber se é possível alterar o tamanho do PDF gerado. O pdf é gerado em uma folha A4, gostaria alterar para 5.4 x 8.5, e se possível, e poderem me auxiliar nesse processo ficaria muito grato.

  1. <?php
  2. use \Firebase\JWT\JWT;
  3. require_once('vendor/autoload.php');
  4. class CommonFunctions{
  5.     public static function encodeString($data){
  6.         $cripto "i3XyKpfdyWWb5&3#dfj@)]*jd";
  7.         $encoded JWT::encode($data$cripto);
  8.         return $encoded;
  9.     }
  10.     public static function decodeString($data){
  11.         $cripto "i3XyKpfdyWWb5&3#dfj@)]*jd";
  12.         //$decoded = JWT::decode($data, $cripto, 'HS256');
  13.         $decoded JWT::decode($data$cripto, array('HS256'));
  14.         return $decoded;
  15.     }
  16.     public static function get_occurrences_between($str$startDelimiter$endDelimiter) {
  17.         $contents = array();
  18.         $startDelimiterLength strlen($startDelimiter);
  19.         $endDelimiterLength strlen($endDelimiter);
  20.         $startFrom $contentStart $contentEnd 0;
  21.         while (false !== ($contentStart strpos($str$startDelimiter$startFrom))) {
  22.             $contentStart += $startDelimiterLength;
  23.             $contentEnd strpos($str$endDelimiter$contentStart);
  24.             if (false === $contentEnd) {
  25.                 break;
  26.             }
  27.             $contents[] = substr($str$contentStart$contentEnd $contentStart);
  28.             $startFrom $contentEnd $endDelimiterLength;
  29.         }
  30.         return $contents;
  31.     }
  32.     public static function getImagesInContent($id$folder$content){
  33.         $finfo = new finfo(FILEINFO_MIME_TYPE);
  34.         $toMaintain = [];
  35.         $listSource = [];
  36.         $listTarget = [];
  37.         $matches CommonFunctions::get_occurrences_between($content"<img""/>");
  38.         foreach ($matches as $match) {
  39.             $sources CommonFunctions::get_occurrences_between($match"src=\"""\"");
  40.             foreach ($sources as $source) {
  41.                 if(CommonFunctions::startsWith($source$folder)){
  42.                     $source str_replace("{$folder}/"""$source);
  43.                     if(!in_array($source$toMaintain)){
  44.                         $toMaintain[] = $source;
  45.                     }
  46.                 } else if(CommonFunctions::startsWith($source"tmp/")){
  47.                     if (file_exists($source) && !is_dir($source)){
  48.                         $extensao $finfo->file($source);
  49.                         if(in_array($extensao, array('image/png''image/jpeg''image/jpg'))){
  50.                             $extension pathinfo($sourcePATHINFO_EXTENSION);
  51.                             $target $folder '/' date('d_m_Y_h_i_s') . '_' rand() . '.' $extension;
  52.                             if(!file_exists($target)){
  53.                                 // move to the target directory
  54.                                 rename($source$target);
  55.                                 $listSource[] = $source;
  56.                                 $listTarget[] = $target;
  57.                                 $toMaintain[] = str_replace("{$folder}/"""$target);
  58.                             }
  59.                         }
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.         return array($toMaintain$listSource$listTarget);
  65.     }
  66.     public static function startsWith($haystack$needle){
  67.         $length strlen($needle);
  68.         return (substr($haystack0$length) === $needle);
  69.     }
  70.     public static function getAddress($lat$lng){
  71.         $formatted_address "";
  72.         if($lat != NULL && strlen(trim($lat)) > && $lng != NULL && strlen(trim($lng)) > 0){
  73.             $key 'AIzaSyCtY1Yio0W9gZFVIEGZKbR-t6aL5353gDI';
  74.             @$json file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$lat},{$lng}&key={$key}");
  75.             if($json != FALSE){
  76.                 $decode json_decode($json);
  77.                 if($decode != NULL && $decode->status == 'OK'){
  78.                     if(count($decode->results) > 0){
  79.                         $result $decode->results["0"];
  80.                         if(property_exists($result"formatted_address") && strlen(trim($result->formatted_address)) > 0){
  81.                             $formatted_address $result->formatted_address;
  82.                         }
  83.                     }
  84.                 }
  85.             }
  86.         }
  87.         return $formatted_address;
  88.     }
  89.     public static function getCoordinates($address){
  90.         $coordinates = array();
  91.         if($address != NULL && strlen(trim($address)) > 0){
  92.             $address str_replace(" ""+"$address);
  93.             $key 'AIzaSyCtY1Yio0W9gZFVIEGZKbR-t6aL5353gDI';
  94.             @$json file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key={$key}");
  95.             if($json != FALSE){
  96.                 $decode json_decode($json);
  97.                 if($decode != NULL && $decode->status == 'OK'){
  98.                     if(count($decode->results) > 0){
  99.                         $result $decode->results["0"];
  100.                         if(property_exists($result"geometry") && strlen(trim($result->geometry->location->lat)) > 0){
  101.                             $coordinates = array($result->geometry->location->lat$result->geometry->location->lng);
  102.                         }
  103.                     }
  104.                 }
  105.             }
  106.         }
  107.         return $coordinates;
  108.     }
  109.     public static function generateServicoPDF$arquivo$key ){
  110.         try{
  111.             TTransaction::open('permission');
  112.             $object = new GeralServico($key);
  113.             $usuario = new GeralUsuario($object->fk_id_usuario);
  114.             $time strtotime($object->data_hora);
  115.             $data TDate::date2br($object->data_hora);
  116.             $dataResposta date('d/m/Y'strtotime($object->data_hora " +21 days"));
  117.             $data_hora $data " às " .  date('H:i'$time);
  118.             if($object->fk_id_status_servico != NULL){
  119.                 $status = new GeralStatusServico($object->fk_id_status_servico);
  120.                 $object->fk_id_status_servico $status->nome;
  121.             }
  122.             $tipo = new GeralTipoServicoDenuncia($object->fk_id_tipo_servico);
  123.             $html '
  124.                 <html>
  125.                     <head>
  126.                         <style>
  127.                             *{
  128.                                 padding: 0;
  129.                                 margin: 0;
  130.                             }
  131.                             p{
  132.                                 font-family: Calibri, Helvetica, Arial, sans-serif;
  133.                             }
  134.                             div.caixa{
  135.                                 width: 359px;
  136.                                 height: 230px;
  137.                                 border: 1px solid black;
  138.                             }
  139.                             div.div_escola{
  140.                                 width: 50px;
  141.                                 height: 229px;
  142.                                 float: left;
  143.                                 background-color: #2E5292;
  144.                                 border-right: 0.5px solid black;
  145.                             }
  146.                             div.info_estudante{
  147.                                 width: 300px;
  148.                                 height: 229px;
  149.                                 float: left;
  150.                                 padding-left: 8px;
  151.                             }
  152.                             .nome_escola{
  153.                                 color: #fff;
  154.                             }
  155.                             .identificacao{
  156.                                 margin-top: 14px;
  157.                                 margin-bottom: 30px;
  158.                                 margin-left: 17px;
  159.                                 color: #2E5292;
  160.                                 font-size: 16px;
  161.                                 font-align: center;
  162.                                 font-weight: bold;
  163.                             }
  164.                             .nome_estudante{
  165.                                 font-size: 12px;
  166.                                 font-weight: bold;
  167.                                 margin-bottom: 25px;
  168.                             }
  169.                             .matricula{
  170.                                 font-size: 10px;
  171.                             }
  172.                             .ft_estudante{
  173.                                 position: absolute;
  174.                                 margin-left: 218px;
  175.                                 margin-top: -170px;
  176.                             }
  177.                             .ft_prefeitura{
  178.                                 margin-top: 35px;
  179.                             }
  180.                             .titulo6{
  181.                                 margin-top: 7px;
  182.                                 font-size: 8px;
  183.                             }
  184.                             .qrcode{
  185.                                 position: absolute;
  186.                                 margin-top: 5px;
  187.                                 margin-left: 235px;
  188.                             }
  189.                             .div_img{
  190.                                 margin-left: 13px;
  191.                                 margin-top: 14px;
  192.                             }
  193.                         </style>
  194.                     </head>
  195.                     <body>
  196.                         <div class="noheader">
  197.                             <div class="caixa">
  198.                                 <div class="div_escola">
  199.                                     <div class="div_img">
  200.                                         <img src="app/images/logo/escola_amelia.png" height="200" width="30">
  201.                                     </div>
  202.                                 </div>
  203.                                 <div class="info_estudante">
  204.                                     <p class="identificacao">IDENTIFICAÇÃO DO ESTUDANTE</p>
  205.                                     <p class="nome_estudante">RICARDO CARVALHO RIOS</p>
  206.                                     <p class="matricula">Matrícula: 2019100201</p>
  207.                                     <div class="ft_prefeitura">
  208.                                         <img src="app/images/logo/prefeitura.jpg" height="52" width="66">
  209.                                     <p class="titulo6">Secretaria Municipal da Educação de Salvador</p>
  210.                                     </div>
  211.                                     <div class="ft_estudante">
  212.                                         <img src="app/images/logo/usuario.png" height="100" width="72">
  213.                                     </div>
  214.                                     <div class="qrcode">
  215.                                         <img src="app/images/logo/qrcode.png" height="60" width="60">
  216.                                     </div>
  217.                                 </div>
  218.                             </div>
  219.                         </div>
  220.                     </body>
  221.                 </html>
  222.             ';
  223.             $mpdf = new \Mpdf\Mpdf();
  224.             $mpdf->useSubstitutions false;
  225.             $mpdf->simpleTables true// set if you do not need complex table borders (mPDF >= 4.3)
  226.             $mpdf->WriteHTML($html);
  227.             $mpdf->Output($arquivo, \Mpdf\Output\Destination::FILE);
  228.             TTransaction::close();
  229.         } catch (Exception $e) {
  230.             new TMessage('error'$e->getMessage());
  231.             TTransaction::rollback();
  232.         }
  233.     }
  234. }
  235. ?>


Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (1)


NR

Não costumo usar a mpdf, mas imagino que tenha essa opção. Você verificou a documentação?
https://mpdf.github.io/