1

我有一个儿童卡片项目,孩子从特定背景中选择背景并写下他的名字并打印但问题是我只想打印卡片(带背景的 apDiv14)而不是整页或者如果有办法将某些内容转换为图片以进行打印

    <div id="apDiv14">
      <div id="for1">
        <h1 ID="head1">&nbsp;<br>
        <h1 ID="head2">&nbsp;<br>
        <h1 ID="head3">&nbsp;<br>
          <br>
        </h1>
    </div>
      <div id="apDiv17"><form name="form1">

        <p>
<br>
  <input type="text" name="newtitle" size="25">
  </p>
          <input type="text" name="newtitle2" size="25">
          <br>
          <br>
          <select name="newtitle3" style="width: 150px;">
    <option value="">age</option>

  </select>
  <br>
        </p>
        <p>          <img src="img/BB.gif" width="80" height="45" onClick="ChangeTitle();"><img src="img/PB.gif" width="80" height="45" onClick="pri();">        </p>
        <p>
  </form>   </div></div>

    <script>
function pri() {
    window.print(); }
</script>

    function pic1(apDiv14)
{
    // background 1
document.getElementById("apDiv14").style.backgroundImage="url('img/1st card Jeddah.jpg')";
document.body.style.zIndex='4';
document.getElementById("apDiv14").style.backgroundSize = "527px 307px";
document.getElementById("apDiv14").style.backgroundRepeat='no-repeat';

}
function pic2(apDiv14)
{
//background 2
document.getElementById("apDiv14").style.backgroundImage= "url('img/2nd card Jeddah.jpg')";
document.body.style.zIndex='4';
document.getElementById("apDiv14").style.backgroundSize = "527px 307px";
document.getElementById("apDiv14").style.backgroundRepeat='no-repeat';}
4

2 回答 2

0

javascript代码:

  var content = document.getElementById("divcontents");
    var pri = document.getElementById("ifmcontentstoprint").contentWindow;
    pri.document.open();
    pri.document.write(content.innerHTML);
    pri.document.close();
    pri.focus();
    pri.print();

html代码:

<iframe id="ifmcontentstoprint" style="height: 0px; width: 0px; position: absolute"></iframe>
于 2013-06-17T06:26:18.603 回答
0

您可以使用打印媒体样式表来限制打印哪些内容(通过将其他内容设置为display: none但大多数浏览器配置为不打印背景图像(因为它们很少重要并且使用大量墨水)。

我会通过使用一些服务器端代码来生成用于打印的 PDF 版本并使用表单将选项提交给服务器来解决此问题。

于 2013-06-17T06:04:08.803 回答