以下代码来自我的resume.php 文件。我尝试将页面分为两个块,每个块使用 (.left) 和 (.right) 类表示。左侧块的内容正在显示,但在右侧,我写的任何内容都会移动到下一页。
<?php
// get all the data
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'] == null ? "" : $_POST['middlename'];
$lastname = $_POST['lastname'];
$designation = $_POST['designation'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$address = $_POST['address'];
$summary = $_POST['summary'];
//get skills
$skills = $_POST['skills'];
require_once('./dompdf/autoload.inc.php');
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
$html = "
<html>
<head>
<style>
body{
font-family: 'Arial', sans-serif;
}
.left{
background-color: rgb(7,72,70);
height:100%;
width: 40%;
color:white;
}
.right{
width:60%;
}
.image-container{
width:2.5in;
height:2.5in;
background-color:red;
}
.name{
width:100%;
height:0.5in;
font-style:bold;
font-size: 0.208in;
text-align:center;
}
.horizontal-line{
height:0.0208in;
width:60%;
margin-left:auto;
margin-right:auto;
color:white;
}
.designation{
text-align:center;
}
.phone, .email, .address, .about{
margin:0.1in;
}
.left-heading{
margin-left:0.2in;
font-style:bold;
margin-top:0.2in;
margin-bottom:0.2in;
}
.left-sub-section{
margin-left:0.2in;
margin-right:0.2in;
}
.right-heading{
margin-left:0.3in;
margin-bottom:0.2in;
margin-top:0.5in;
}
</style>
</head>
<body>
<div class='container'>
<div class='left'>
<div class='image-container'>
</div>
<div class='name'>
$firstname $middlename $lastname
</div>
<div class='horizontal-line'>
</div>
<div class='designation'>
$designation
</div>
<div class='left-heading'>
About
</div>
<div class='left-sub-section'>
<div class='phone'>$phone</div>
<div class='email'>$email</div>
<div class='address'>$address</div>
<div class='about'>$summary</div>
</div>
<div class='left-heading'> Skills </div>
<div class='left-sub-section'> ";
foreach ($skills as $skill){
$html .= "<div style='margin:0.1in;'> $skill</div>";
}
$html .= "</div>
</div>
<div class='right'>
<div class='ahivements-section'>
<div class='right-heading'>
ACHIEVEMENT
</div>
</div>
</div>
</div>
</body>
</html>";
$dompdf->loadHtml($html);
// Render the HTML as PDF
$dompdf->render();
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="output.pdf"'); // Set filename as "output.pdf" and specify inline disposition
// Output the generated PDF to Browser
$dompdf->stream(null, ['Attachment' => 0]);
我想在同一页面的右侧获得“成就”部分。
对
display:inline-block
和 .left
使用 .right
,以便它们可以彼此相邻显示,并且可以稍微减小它们的宽度,这样它的总和就不会正好达到 100%,而是稍微少一点,另外还可以在它们上使用 box-sizing: border-box
来包含这些百分比宽度值中的所有边框和填充。 (通过反复试验来找出哪些百分比值有效)