Set Printing Preferences from JS

前端 未结 4 2037
南旧
南旧 2020-12-15 18:24

So... from what I can find on the Google, I can\'t find a way to use Javascript to set my printing preferences (read: margins, orientations, footer, etc).

I am abou

4条回答
  •  悲哀的现实
    2020-12-15 19:05

    I think you're pretty much out of luck trying to do this in HTML and CSS. A big part of the issue is that printer margins are all specific to the type of printer: Most printers have a minimum margin they can set (equivalent to the space they need to grip the page, and the left/right movement of the head.

    Acceptable margins will also vary based on paper size (the margin can typically be smaller on a smaller sheet than the maximum the printer will accept). For instance, if you load A5 paper into an A4 printer, the margins you can set will be different than if you load A4.

    None of that information is available to the webpage, via CSS, javascript, or anything.

    Now, as far as a solution goes, PDF files do allow you to embed some printer default settings within the file - Acrobat pro will allow you to specify scaling options, default numbers of copies, etc. I wouldn't mind betting that there are more potential settings available in the file format that Acrobat doesn't expose.

    There are plenty of full-featured PDF generation tools for whichever server-side technology you use. the good ones will even allow you to provide a URL, and render HTML+CSS to PDF content - that would automate the generation to some extent. PDF generation is pretty CPU intensive though, and it wouldn't be seamless to the user, either (and would require PDF plugins for most browsers).

    I know it's not ideal, but it's the avenue I'd look into. Good luck!

提交回复
热议问题