如何使用JS Print Setup插件打印网页的特定部分

时间:2016-08-24 17:48:45

标签: javascript php jquery mozilla add-on

我的网页需要打印一些数据。我正在使用" JS Print Setup"附加(Mozilla fire fox)打印。在这里,我只想从我的网页打印特定内容。谁能帮我。我的代码是



function test2() {
   
   
   jsPrintSetup.setPaperSizeUnit(jsPrintSetup.kPaperSizeMillimeters);
   jsPrintSetup.definePaperSize(44, 44, "na_label", 'na_label_51x25mm', "The Quarry", "100", "100", jsPrintSetup.kPaperSizeMillimeters);
   jsPrintSetup.setPaperSizeData(44);
   jsPrintSetup.setOption('shrinkToFit', true);
   
   
  jsPrintSetup.clearSilentPrint();  
  jsPrintSetup.setSilentPrint(1); 

  jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);
  // Reduce margins
  jsPrintSetup.setOption('unwriteableMarginTop', 0);
  jsPrintSetup.setOption('unwriteableMarginLeft', 0);
  jsPrintSetup.setOption('unwriteableMarginBottom', 0);
  jsPrintSetup.setOption('unwriteableMarginRight', 0);

  jsPrintSetup.setOption('marginTop',0);
  jsPrintSetup.setOption('marginBottom',0);
  jsPrintSetup.setOption('marginLeft',10);
  jsPrintSetup.setOption('marginRight',0);

  // Empty headers & footers
  jsPrintSetup.setOption('headerStrLeft', '');
  jsPrintSetup.setOption('headerStrCenter', '');
  jsPrintSetup.setOption('headerStrRight', '');
  jsPrintSetup.setOption('footerStrLeft', '');
  jsPrintSetup.setOption('footerStrCenter', '');
  jsPrintSetup.setOption('footerStrRight', '');

  jsPrintSetup.setOption('printRange', jsPrintSetup.kRangeSpecifiedPageRange);
  jsPrintSetup.setOption('startPageRange', '<div id="testfff">');
  jsPrintSetup.setOption('endPageRange', '</div>');
  
  jsPrintSetup.print();
  
}
&#13;
<a href="javascript: test2();">Test1</a>

<div id="testfff"> 
   <table width="50mm">
      <tr>
         <th>Name</th>
         <th>Mark</th>
      </tr>
      <tr>
         <td>Shihab</td>
         <td>25</td>
      </tr>
      <tr>
         <td>Shihab</td>
         <td>25</td>
      </tr>
      <tr>
         <td>Shihab</td>
         <td>25</td>
      </tr>
      <tr>
         <td>Shihab</td>
         <td>25</td>
      </tr>
   </table>   
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案