简体   繁体   English

打印带有附加内容的传单地图

[英]Printing a leaflet map with additional content

Hi asking advice on how to print a leaflet map but with added content.嗨,请咨询有关如何打印传单地图但添加内容的建议。 We've tried the leaflet.browser.print using the custum print.我们已经尝试过使用 custum 打印的 Leaflet.browser.print。 But in some cases not all the map and the summary table does not fill the printing preview.但在某些情况下,并不是所有的地图和汇总表都没有填满打印预览。

Here is the implementation code:下面是实现代码:

         L.control.browserPrint({
            title: thisBlock.name,
            printModes: ["Custom"]
        }).addTo(map)

This is what we need - it must always show the full map and the table below:这就是我们需要的 - 它必须始终显示完整的地图和下表:

but this is how it is showing - not full screen:但这就是它的显示方式 - 不是全屏:

Also tried to add the event:还尝试添加事件:

        map.on("browser-print", function (e) {
            //Would like to resize the map with the summary table here to fit the page size preview.
        });

How to get the dimensions of the target page and the objects that will be placed on the printing preview and then how to resize it.如何获取目标页面的尺寸和将放置在打印预览上的对象,然后如何调整它的大小。 And will it work if the user change the printing settings and will the objects then size accordingly?如果用户更改打印设置并且对象会相应地调整大小,它会起作用吗?

How to get the dimensions of the target page?如何获取目标页面的尺寸?

You can not.你不能。 There is no way for JS or CSS code to know whether the user wants to print in DIN A4 paper, or A3, or US letter. JS 或 CSS 代码无法知道用户是想用 DIN A4 纸、A3 纸还是 US letter 打印。 The current techniques are hackish at best. 当前的技术充其量只是黑客。 On top of that, there is no known way to know the size of the printable area (paper size minus printer-imposed margins), and there is no way to know if the user is gonna use print scaling.最重要的是,没有已知的方法可以知道可打印区域的大小(纸张大小减去打印机强加的边距),也无法知道用户是否要使用打印缩放。

IMO, your best approach is gonna be: IMO,您最好的方法是:

1- Use CSS @media print queries, eg: 1-使用 CSS @media print查询,例如:

@media print {
  #leaflet-map { border: 1px solid black; }
}

The CSS rules in there will apply only when printing (and not when displaying on a screen).那里的 CSS 规则仅适用于打印时(而不是在屏幕上显示时)。 Read more about CSS @media here .在此处阅读有关CSS @media更多信息。

2- Use mm , cm or in units for the length of your CSS rules. 2 -使用mmcmin单位为你的CSS规则的长度。 eg:例如:

@media print {
  #leaflet-map { width: 17.5cm; height: 20cm; }
  #table-with-data { width:17cm; height: 5cm; }
}

Keep in mind that this is the size before the browser applies print scaling .请记住,这是浏览器应用打印缩放之前的大小。 You might need to instruct your users to keep an eye on that, and always print stuff at "100% scale".您可能需要指示您的用户注意这一点,并始终以“100% 比例”打印内容。

3- Use a CSS @page size hint . 3-使用CSS @page size提示 Note that this is experimental (at the time of this writing) and is just a hint, a suggestion.请注意,这是实验性的(在撰写本文时),只是一个提示,一个建议。 Browsers are free to ignore this.浏览器可以随意忽略这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM