To add a 0.5 cm border around the entire page in your PDF, you can use CSS to define the border and ensure it spans the full width and height of the page. Since this HTML is likely being converted to a PDF using a tool like Puppeteer, wkhtmltopdf, or similar, you can use the @page rule in CSS along with some adjustments to ensure the border appears correctly.
Here’s how you can modify your existing HTML and CSS to include a 0.5 cm border around the entire page:
Updated Code with Page Border
<html>
<head>
<meta charset="utf-8">
<style>
/* Define the font face */
@font-face {
font-family: 'NotoMalayalam';
src: url('${fontBase64}') format('truetype');
}
/* General body styling */
body {
font-family: 'NotoMalayalam', sans-serif;
font-size: 14px;
line-height: 1.6;
margin: 0; /* Remove default margins */
padding: 0.5cm; /* Add padding for the border */
box-sizing: border-box;
}
/* Add a border around the entire page */
@page {
size: A4;
margin: 0; /* Remove default page margins */
}
body {
border: 2px solid black; /* Add a 2px border (adjust thickness as needed) */
height: calc(29.7cm - 1cm); /* A4 height minus 0.5cm top/bottom padding */
width: calc(21cm - 1cm); /* A4 width minus 0.5cm left/right padding */
margin: 0.5cm auto; /* Center the content with 0.5cm margin */
box-sizing: border-box;
}
/* Letterhead styling */
.letterhead {
text-align: center;
margin-bottom: 20px;
}
.org-title {
font-size: 18px;
font-weight: bold;
}
.org-subtitle {
font-size: 12px;
}
.office-info {
margin-top: 10px;
font-size: 13px;
}
hr {
margin-top: 12px;
margin-bottom: 20px;
}
h1 {
text-align: center;
font-size: 16px;
margin-bottom: 24px;
text-decoration: underline;
}
.line {
margin-bottom: 12px;
}
</style>
</head>
<body>
<div class="letterhead">
<div class="org-title">കേരള സ്റ്റേറ്റ് ഇലക്ട്രിസിറ്റി ബോർഡ് ലിമിറ്റഡ്</div>
<div class="org-subtitle">(Incorporated under the Indian Companies Act-1956)</div>
<div class="office-info">
Office of the Assistant Engineer<br>
${data.sectionName} (${data.sectionCode})<br>
${data.sectionAddress1}, ${data.sectionAddress2}<br>
ഫോൺ: ${data.sectionPhone} | ഇമെയിൽ: ${data.sectionMail}
</div>
</div>
<hr>
<h1>പോലീസ് സ്റ്റേഷനിലേക്ക് അപേക്ഷ</h1>
<div class="line">ഫയൽ നമ്പർ: ${data.DBFlieNumber} തീയതി: ${data.DBFlieDate}</div>
<div class="line">സ്ഥലം: ${data.DashingSite}</div>
<div class="line">വാഹനം: ${data.DashingVehicleNum}</div>
<div class="line">തീയതി/സമയം: ${data.DashingDate} - ${data.DashingTime}</div>
<div class="line">പോലീസ് സ്റ്റേഷൻ: ${data.PoliceStation}</div>
<div class="line">അപേക്ഷ നമ്പർ: ${data.PoliceStationrequestFileNo}</div>
<div class="line">MACT കോടതി: ${data.MACTCourt}</div>
</body>
</html>
Explanation of Changes
-
Page Dimensions and Margins:
- The
@page rule ensures that the PDF uses A4 dimensions (21cm x 29.7cm) and removes default margins.
- The
body element is styled with a 0.5cm padding to create space for the border.
-
Border Styling:
- A
2px solid black border is applied to the body element. You can adjust the thickness (2px) as needed.
-
Content Sizing:
- The
body height and width are calculated to fit within the A4 dimensions, accounting for the 0.5cm padding on all sides.
-
Centering Content:
- The
margin: 0.5cm auto ensures the content is centered horizontally and vertically within the page.
-
Box Sizing:
- The
box-sizing: border-box property ensures that padding and borders are included in the element's total dimensions.
Notes
- Ensure that the tool you are using to generate the PDF supports the
@page rule and custom CSS.
- If the border does not appear as expected, verify that the PDF generation tool respects the
border and padding properties.
- Adjust the
0.5cm padding and 2px border thickness as needed to meet your exact requirements.
This approach should produce a PDF with a 0.5 cm border around the entire page while maintaining the layout of your content.