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.
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.
- <?php
- use \Firebase\JWT\JWT;
- require_once('vendor/autoload.php');
- class CommonFunctions{
- public static function encodeString($data){
- $cripto = "i3XyKpfdyWWb5&3#dfj@)]*jd";
- $encoded = JWT::encode($data, $cripto);
- return $encoded;
- }
- public static function decodeString($data){
- $cripto = "i3XyKpfdyWWb5&3#dfj@)]*jd";
- //$decoded = JWT::decode($data, $cripto, 'HS256');
- $decoded = JWT::decode($data, $cripto, array('HS256'));
- return $decoded;
- }
- public static function get_occurrences_between($str, $startDelimiter, $endDelimiter) {
- $contents = array();
- $startDelimiterLength = strlen($startDelimiter);
- $endDelimiterLength = strlen($endDelimiter);
- $startFrom = $contentStart = $contentEnd = 0;
- while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
- $contentStart += $startDelimiterLength;
- $contentEnd = strpos($str, $endDelimiter, $contentStart);
- if (false === $contentEnd) {
- break;
- }
- $contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
- $startFrom = $contentEnd + $endDelimiterLength;
- }
- return $contents;
- }
- public static function getImagesInContent($id, $folder, $content){
- $finfo = new finfo(FILEINFO_MIME_TYPE);
- $toMaintain = [];
- $listSource = [];
- $listTarget = [];
- $matches = CommonFunctions::get_occurrences_between($content, "<img", "/>");
- foreach ($matches as $match) {
- $sources = CommonFunctions::get_occurrences_between($match, "src=\"", "\"");
- foreach ($sources as $source) {
- if(CommonFunctions::startsWith($source, $folder)){
- $source = str_replace("{$folder}/", "", $source);
- if(!in_array($source, $toMaintain)){
- $toMaintain[] = $source;
- }
- } else if(CommonFunctions::startsWith($source, "tmp/")){
- if (file_exists($source) && !is_dir($source)){
- $extensao = $finfo->file($source);
- if(in_array($extensao, array('image/png', 'image/jpeg', 'image/jpg'))){
- $extension = pathinfo($source, PATHINFO_EXTENSION);
- $target = $folder . '/' . date('d_m_Y_h_i_s') . '_' . rand() . '.' . $extension;
- if(!file_exists($target)){
- // move to the target directory
- rename($source, $target);
- $listSource[] = $source;
- $listTarget[] = $target;
- $toMaintain[] = str_replace("{$folder}/", "", $target);
- }
- }
- }
- }
- }
- }
- return array($toMaintain, $listSource, $listTarget);
- }
- public static function startsWith($haystack, $needle){
- $length = strlen($needle);
- return (substr($haystack, 0, $length) === $needle);
- }
- public static function getAddress($lat, $lng){
- $formatted_address = "";
- if($lat != NULL && strlen(trim($lat)) > 0 && $lng != NULL && strlen(trim($lng)) > 0){
- $key = 'AIzaSyCtY1Yio0W9gZFVIEGZKbR-t6aL5353gDI';
- @$json = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?latlng={$lat},{$lng}&key={$key}");
- if($json != FALSE){
- $decode = json_decode($json);
- if($decode != NULL && $decode->status == 'OK'){
- if(count($decode->results) > 0){
- $result = $decode->results["0"];
- if(property_exists($result, "formatted_address") && strlen(trim($result->formatted_address)) > 0){
- $formatted_address = $result->formatted_address;
- }
- }
- }
- }
- }
- return $formatted_address;
- }
- public static function getCoordinates($address){
- $coordinates = array();
- if($address != NULL && strlen(trim($address)) > 0){
- $address = str_replace(" ", "+", $address);
- $key = 'AIzaSyCtY1Yio0W9gZFVIEGZKbR-t6aL5353gDI';
- @$json = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key={$key}");
- if($json != FALSE){
- $decode = json_decode($json);
- if($decode != NULL && $decode->status == 'OK'){
- if(count($decode->results) > 0){
- $result = $decode->results["0"];
- if(property_exists($result, "geometry") && strlen(trim($result->geometry->location->lat)) > 0){
- $coordinates = array($result->geometry->location->lat, $result->geometry->location->lng);
- }
- }
- }
- }
- }
- return $coordinates;
- }
- public static function generateServicoPDF( $arquivo, $key ){
- try{
- TTransaction::open('permission');
- $object = new GeralServico($key);
- $usuario = new GeralUsuario($object->fk_id_usuario);
- $time = strtotime($object->data_hora);
- $data = TDate::date2br($object->data_hora);
- $dataResposta = date('d/m/Y', strtotime($object->data_hora . " +21 days"));
- $data_hora = $data . " às " . date('H:i', $time);
- if($object->fk_id_status_servico != NULL){
- $status = new GeralStatusServico($object->fk_id_status_servico);
- $object->fk_id_status_servico = $status->nome;
- }
- $tipo = new GeralTipoServicoDenuncia($object->fk_id_tipo_servico);
- $html = '
- <html>
- <head>
- <style>
- *{
- padding: 0;
- margin: 0;
- }
- p{
- font-family: Calibri, Helvetica, Arial, sans-serif;
- }
- div.caixa{
- width: 359px;
- height: 230px;
- border: 1px solid black;
- }
- div.div_escola{
- width: 50px;
- height: 229px;
- float: left;
- background-color: #2E5292;
- border-right: 0.5px solid black;
- }
- div.info_estudante{
- width: 300px;
- height: 229px;
- float: left;
- padding-left: 8px;
- }
- .nome_escola{
- color: #fff;
- }
- .identificacao{
- margin-top: 14px;
- margin-bottom: 30px;
- margin-left: 17px;
- color: #2E5292;
- font-size: 16px;
- font-align: center;
- font-weight: bold;
- }
- .nome_estudante{
- font-size: 12px;
- font-weight: bold;
- margin-bottom: 25px;
- }
- .matricula{
- font-size: 10px;
- }
- .ft_estudante{
- position: absolute;
- margin-left: 218px;
- margin-top: -170px;
- }
- .ft_prefeitura{
- margin-top: 35px;
- }
- .titulo6{
- margin-top: 7px;
- font-size: 8px;
- }
- .qrcode{
- position: absolute;
- margin-top: 5px;
- margin-left: 235px;
- }
- .div_img{
- margin-left: 13px;
- margin-top: 14px;
- }
- </style>
- </head>
- <body>
- <div class="noheader">
- <div class="caixa">
- <div class="div_escola">
- <div class="div_img">
- <img src="app/images/logo/escola_amelia.png" height="200" width="30">
- </div>
- </div>
- <div class="info_estudante">
- <p class="identificacao">IDENTIFICAÇÃO DO ESTUDANTE</p>
- <p class="nome_estudante">RICARDO CARVALHO RIOS</p>
- <p class="matricula">Matrícula: 2019100201</p>
- <div class="ft_prefeitura">
- <img src="app/images/logo/prefeitura.jpg" height="52" width="66">
- <p class="titulo6">Secretaria Municipal da Educação de Salvador</p>
- </div>
- <div class="ft_estudante">
- <img src="app/images/logo/usuario.png" height="100" width="72">
- </div>
- <div class="qrcode">
- <img src="app/images/logo/qrcode.png" height="60" width="60">
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>
- ';
- $mpdf = new \Mpdf\Mpdf();
- $mpdf->useSubstitutions = false;
- $mpdf->simpleTables = true; // set if you do not need complex table borders (mPDF >= 4.3)
- $mpdf->WriteHTML($html);
- $mpdf->Output($arquivo, \Mpdf\Output\Destination::FILE);
- TTransaction::close();
- } catch (Exception $e) {
- new TMessage('error', $e->getMessage());
- TTransaction::rollback();
- }
- }
- }
- ?>
Não costumo usar a mpdf, mas imagino que tenha essa opção. Você verificou a documentação?
https://mpdf.github.io/