selectpdf html到pdf制作图像和页面相等大小

发布于 2025-01-26 06:12:19 字数 603 浏览 2 评论 0原文

我用HTML生成一张卡,然后用SelectPDF转换器将其转换为PDF。问题是,我似乎无法完全适合卡和PDF页面,没有“白皮书”。 我的目标是卡和PDF页面的大小相同,因此我可以打印它。

代码(C#):

HtmlToPdf converter = new HtmlToPdf();
var doc = new PdfDocument();
converter.Options.PdfPageSize = PdfPageSize.Custom;
converter.Options.PdfPageCustomSize = new SizeF(Convert.ToInt32(paperWidth), Convert.ToInt32(paperHeight));
doc = converter.ConvertHtmlString(cardString);
return doc.Save();

I generate a card with html and then I convert it to pdf with SelectPdf converter. The problem is, I can't seem to fit the card and pdf page perfectly, without no "white paper".
My goal is that the card and pdf page are the same size, so i can print it.

Card on pdf page example

the code (c#):

HtmlToPdf converter = new HtmlToPdf();
var doc = new PdfDocument();
converter.Options.PdfPageSize = PdfPageSize.Custom;
converter.Options.PdfPageCustomSize = new SizeF(Convert.ToInt32(paperWidth), Convert.ToInt32(paperHeight));
doc = converter.ConvertHtmlString(cardString);
return doc.Save();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2025-02-02 06:12:19

如果您使用div元素,则在CSS中可以使用@Media打印在打印时指定格式。

<html>
<style>
@media print {
        body{
            width: 21cm;
            height: 29.7cm;
       } 
    }
    body {
        margin: 0;
        padding: 0;
    }

    .pageA4 {
        width: 210mm;
        height: 297mm;
    }
</style>
<html>
<head>
</head>
<body>
    <div class="pageA4" style="background-color:yellow"><h1>page 1</h1></div>
   
</body>
</html>

如果您想了解更多信息,请阅读

If you use divelement, in CSS you can use @media print to specify formatting when printed.

<html>
<style>
@media print {
        body{
            width: 21cm;
            height: 29.7cm;
       } 
    }
    body {
        margin: 0;
        padding: 0;
    }

    .pageA4 {
        width: 210mm;
        height: 297mm;
    }
</style>
<html>
<head>
</head>
<body>
    <div class="pageA4" style="background-color:yellow"><h1>page 1</h1></div>
   
</body>
</html>

If you want to know more , read this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文