尝试使用
HTML
、JavaScript
或 Java
或依赖项以编程方式将生成的空手道 Karate
报告从目标文件夹转换为 pdf 格式。
您能帮助我们吗?
在此示例中,单击按钮时,#content div 内的内容将转换为 PDF 并下载:
document.getElementById('download').addEventListener('click', function() {
var content = document.getElementById('content');
var opt = {
margin: 1,
filename: 'karate-report.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
};
// Use the html2pdf.js library to save the content as a PDF
html2pdf().from(content).set(opt).save();
});
body {
font-family: Arial, sans-serif;
}
#content {
border: 1px solid #000;
padding: 10px;
}
button {
margin-top: 20px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML to PDF Converter</title>
</head>
<body>
<div id="content">
<!-- Sample Karate Report HTML content -->
<h1>Karate Test Report</h1>
<p>Test Case 1: Passed</p>
<p>Test Case 2: Failed</p>
<!-- Add more content as needed -->
</div>
<button id="download">Download as PDF</button>
<!-- Including the html2pdf.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.js"></script>
</body>
</html>