duanre4421 2011-11-22 16:41
浏览 106
已采纳

如何强制网页内容填写A4打印页面?

I'm currently building an app for managing a small organization. One of the functions of the app is printing out a bunch of monthly letters to the members. The way it works is I pull data from the DB about the member (name, address, dates, etc...) and then populate a letter template that has placeholder variables for all the details.

After all the letters are populated I need to give the user the option to print the entire block of letters. This is where my problem comes in. I want it so that each letter would print on a single sheet of paper, and the content be centered and aligned in the middle of the page.

I've attempted to make a Print Media stylesheet and inject the content into a div which I then style to fill the page, but this solution doesn't seem to work properly mainly due to layout issues.

Is this something I should be doing with another format? Should I be sending this to Word or PDF for proper handling or is this something that can done with HTML, CSS?

Note: The stack i'm using is bog standard Linux/PHP and I can pretty much install any additional 3rd party library that I might need.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanliao3826 2011-11-22 17:25
    关注

    HTML isn't very good for this job, especially if you have a single HTML page with many letters (i.e. you want each letter to start on a new page).

    There are lots of PDF generation tools for PHP and PDF is actually rather good for print layouts.

    PDF will let you control the fine-grained aspects of printing, such as keeping blocks together, when to start a new page and much, much more!

    Which one is the best PDF-API for PHP?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?