首页 文章

wkhtmltopdf - 禁用分页功能

提问于
浏览
8

我正在尝试将谷歌 Map 嵌入到横向PDF中,但不知何故,wkhtmltopdf总是将 Map 分成两部分,尽管 Map 很容易放在一页上 .

我认为问题是, Map 是用瓷砖建造的 . 瓷砖比 Map 大并且被切断,但是wkhtmltopdf似乎忽略了这一点并且认为切割的瓷砖也必须适合页面...

以下是一些重现此示例的示例代码:

<html>
    <head>
        <script src="https://maps.google.com/maps/api/js?sensor=false"></script>
        <script>
            window.onload = function(){                     
                var fenway = new google.maps.LatLng(47.188563,8.480487);
                var gmap = new google.maps.Map(document.getElementById("map"),{
                    center: fenway,
                    zoom: 14,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    disableDefaultUI: true
                });

                var marker = new google.maps.Marker({
                    position: fenway,
                    map:gmap
                });         

                google.maps.event.addListener(gmap,"tilesloaded",function(){
                    window.status = "ready";
                });
            }
        </script>
    </head>
    <body>
        <div id="map" style="width:1500px;height:800px"></div>
    </body>
</html>

以及将其转换为PDF的命令:

wkhtmltopdf --window-status ready --orientation landscape map.html map.pdf

我顺便使用最新版本的wkhtmltopdf ......

是否有可能使 Map 填满没有剪切的页面?

2 回答

  • 1

    它并不是真正禁用分页符,但设置主体高度确实会在一页上呈现您的 Map .

    <body style="height:1000px;">
        <div id="map" style="width:1500px;height:800px;"></div>
    </body>
    
  • 4

    您可以使用 --page-width--page-height 选项 wkhtmltopdf 指定与页面具有相同宽高比的大小 . 如果要完全用内容填充输出PDF,则'll probably still have to combine this with specifying a width and height on the body, but it'非常有用 .

    作为参考, --page-width--page-height 选项接受的'UnitReal'接受具有单位的浮点值:

    (none) == mm
    mm
    cm == 10mm
    m  == 1000mm
    didot
    inch
    in == inch
    pica
    pc == pica
    cicero
    pixel
    px == pixel
    point
    pt == point
    

    但请注意,它们 must 都指定为相同的单位 .

相关问题