Question:
How to set the full width of the PDF page?

Problem:

In Laravel 10 I'm using the wkhtmltopd library to generate pdf documents.


The problem is when I try to generate content in full width of document, top and sides. For some reason, there is always a white border around the content.


This is my html code that I use to generate document:

<!DOCTYPE html>

<html style="margin: 0; padding: 0; background-color: #fd7e14">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Title</title>

<link rel="stylesheet" media="screen" href="https://fontlibrary.org//face/open-sauce-one" type="text/css"/>

<meta name="author" content="name author">

<style media="all">

    html {

        margin: 0 !important;

        padding:0 !important;

        border:0 !important;

        outline:0 !important;

    }

    body {

        margin: 0 !important;

        padding:0 !important;

        border:0 !important;

        outline:0 !important;

    }

</style>

</head>


<body>

   Test Content

</body>

</html>


Is there something wrong with styles?


Solution:

Your html looks ok to me, but you also need to set all margins to 0 for the PDF document (in addition to the html content). The options for wkhtmltopdf on the command line are as follows:


wkhtmltopdf -T 0 -B 0 -L 0 -R 0 <input_url> <output_file>


It depends on the wrapper used how to set those options in PHP.

See >the manual for further explanations on all options.


Answered by: >volkerschulz

Credit: >Stack Overflow


Read more:

>Use Firebase Realtime Database with ASP.NET MVC App

>Setting up a Cloud Composer environment: Step-by-step guide

>Built Web API using ASP.NET (C#)

>Plugins and Presets for Vuejs project

>How to Create an array based on two other arrays in Php

>Testing react components using Hooks and Mocks


Ritu Singh

Ritu Singh

Submit
0 Answers