首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SelectPDF不打印背景svg图像

SelectPDF不打印背景svg图像
EN

Stack Overflow用户
提问于 2019-04-26 11:55:57
回答 1查看 510关注 0票数 0

我正在尝试将html转换为pdf,其中有svg图像作为背景图像。当使用svg (v2)转换时,它不打印背景selectPdf图像,但如果我使用他们的在线测试页面将相同的html转换为pdf,它可以打印背景图像。

下面是我调用api的方法

代码语言:javascript
复制
 var options = new PdfOptions();
 options.html = html;
 options.key = _key;
 options.margin_bottom = 0;
 options.margin_top = 0;
 options.SetLandscape();

var client = new HttpClient();
var content = new StringContent(JsonConvert.SerializeObject(options, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await client.PostAsync("http://selectpdf.com/api2/convert/", content);

if (!result.IsSuccessStatusCode)
 {
    var msg = await result.Content.ReadAsStringAsync();
    throw new ApplicationException($"Failed to create pdf: {msg}");
 }

return await result.Content.ReadAsStreamAsync();

html代码发送

代码语言:javascript
复制
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width"> 
    <style>

#watermark {
     position: fixed; 
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0ZXh0IHg9IjUlIiB5PSI1JSIgZm9udC1zaXplPSIzMCIgZmlsbD0icmVkIj5JIGxvdmUgU1ZHITwvdGV4dD48L3N2Zz4=);
    height: calc(100% + 50px);
    width: calc(100% + 50px);
    background-size: 270px 160px;
    background-repeat: repeat;
    opacity: 0.3;
    top: -50px;
    z-index:1;
    left: -50px;
}
</style>
</head>
<body>
<div class="grid-container" style="width: 1200px">
<div id="watermark"></div>
    <div class="grid-x grid-padding-x">
    <div class="large-4 cell">
        <h3 style="padding: 0px; margin: 0px; height: 100px; display:table-cell;vertical-align:middle;"><strong></strong></h3>
    </div>

    <div class="large-4 cell text-right">
        <h3 style="padding: 0px; margin: 0px; height: 100px; display:table-cell;vertical-align:middle;">  Specification</h3>
    </div>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. 
    </p>
</div>
</div>
</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2019-05-08 16:39:05

当使用base64编码的画面时,需要额外设置一个接口参数skip_decoding为True。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55860602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档