{"id":243,"date":"2025-03-26T19:26:36","date_gmt":"2025-03-26T19:26:36","guid":{"rendered":"https:\/\/lmponceb.com\/?p=243"},"modified":"2025-08-28T18:11:52","modified_gmt":"2025-08-28T18:11:52","slug":"wkhtmtopdf","status":"publish","type":"post","link":"https:\/\/lmponceb.com\/index.php\/2025\/03\/26\/wkhtmtopdf\/","title":{"rendered":"Como usar dimensiones fijas en cm en WKHTMTOPDF"},"content":{"rendered":"\n<p>Esto se da de la necesidad de hacer que las dimensiones respondan a un A4 y trabajar los diferentes elementos en cm.<\/p>\n\n\n\n<p>Para esto debemos enviar el par\u00e1metro: &#8211;disable-smart-shrinking y setear los par\u00e1metros de margen a 0.<\/p>\n\n\n\n<p>Fuente: <a href=\"https:\/\/github.com\/mikehaertl\/phpwkhtmltopdf\">https:\/\/github.com\/mikehaertl\/phpwkhtmltopdf<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    if(str_starts_with($htmlTemplate,'&lt;!--disable-smart-shrinking--&gt;')){\n        $options&#91;] = 'disable-smart-shrinking';\n        $options&#91;'margin-top']    = 0;\n        $options&#91;'margin-right']  = 0;\n        $options&#91;'margin-bottom'] = 0;\n        $options&#91;'margin-left']   = 0;\n    }<\/code><\/pre>\n\n\n\n<p><strong>Codigo:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!--disable-smart-shrinking--&gt;\n&lt;html&gt;\n    &lt;head&gt;\n        &lt;style type=\"text\/css\"&gt;\n            #test{\n                width:21cm;\n                height:29.7cm;\n                border:1px solid red;\n                background-color:#313131;\n                color:#ffffff;\n                box-sizing: border-box; \n            }\n            body{\n                margin:0px;\n                padding:0px;\n                width:21cm;\n                height:29.7cm;\n            }\n\n        &lt;\/style&gt;\n    &lt;\/head&gt;\n    &lt;body&gt;\n        &lt;div id=\"test\"&gt;\n            Contenido\n        &lt;\/div&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Resultado: <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"1024\" src=\"https:\/\/lmponceb.com\/wp-content\/uploads\/2025\/03\/image-2-735x1024.png\" alt=\"\" class=\"wp-image-244\" srcset=\"https:\/\/lmponceb.com\/wp-content\/uploads\/2025\/03\/image-2-735x1024.png 735w, https:\/\/lmponceb.com\/wp-content\/uploads\/2025\/03\/image-2-215x300.png 215w, https:\/\/lmponceb.com\/wp-content\/uploads\/2025\/03\/image-2.png 747w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/figure>\n\n\n\n<p><strong>Importante:<\/strong>  Es necesario contar con la versi\u00f3n wkhtmltopdf 0.12.6.1 (with patched qt)<\/p>\n\n\n\n<p>se puede verificar ejecutando: <\/p>\n\n\n\n<p class=\"has-light-green-cyan-color has-black-background-color has-text-color has-background has-link-color wp-elements-01d9abfd726bb47be38ca7f7465eaeda\">wkhtmltopdf &#8211;version<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Esto se da de la necesidad de hacer que las dimensiones respondan a un A4 y trabajar los diferentes elementos en cm. Para esto debemos enviar el par\u00e1metro: &#8211;disable-smart-shrinking y setear los par\u00e1metros de margen a 0. Fuente: https:\/\/github.com\/mikehaertl\/phpwkhtmltopdf Codigo: Resultado: Importante: Es necesario contar con la versi\u00f3n wkhtmltopdf 0.12.6.1 (with patched qt) se puede &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lmponceb.com\/index.php\/2025\/03\/26\/wkhtmtopdf\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Como usar dimensiones fijas en cm en WKHTMTOPDF&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":4,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":254,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/posts\/243\/revisions\/254"}],"wp:attachment":[{"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lmponceb.com\/index.php\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}