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?

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?