java itext和dotmatrix打印机
我有一个JSP页面,它只需获取参数、查询数据库、生成发票PDF,然后静默地发送到默认打印机。我使用itext库
发票必须用连续纸张在点阵打印机上打印
每个发票页面的大小为5英寸
如果我选择页面大小为a5,代码将生成一个PDF,如图所示
打印时,它打印一页,另一页留白。用户必须手动将纸张向后滚动
如果我选择pagesize作为a5横向(a5.rotate()),代码会生成一个PDF,如图中所示,这样更好
但当它打印在纸上时,它会开始垂直打印页面,因为打印机有一个a4纸盘
在我看来,我需要将我的打印机定义为具有连续纸张的点矩阵打印机
我使用的代码是:
Document document = new Document(PageSize.A5,0,0,0,0);
try {
PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
document.open();
StringBuffer javascript = new StringBuffer();
javascript.append("this.print({bUI: false, bSilent: true, bShrinkToFit: true});");
PdfAction pdfAction= PdfAction.javaScript(javascript.toString(), writer);
writer.addJavaScript(pdfAction);
writer.addViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
PdfPTable table = new PdfPTable(3); // 3 columns.
table.setWidthPercentage(100);
PdfPCell cell1 = new PdfPCell(new Paragraph(""));
PdfPCell cell2 = new PdfPCell(new Paragraph(""));
PdfPCell cell3 = new PdfPCell(new Paragraph(MakbuzNo,FontFactory.getFont(FontFactory.COURIER,9)));
cell3.setLeading(16f, 0f);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(""));
cell2 = new PdfPCell(new Paragraph(""));
cell3 = new PdfPCell(new Paragraph(Duzenleyen,FontFactory.getFont(FontFactory.COURIER,9)));
cell3.setLeading(16f, 0f);
cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(MSISDN,FontFactory.getFont(FontFactory.COURIER,9)));
cell2 = new PdfPCell(new Paragraph(""));
cell3 = new PdfPCell(new Paragraph(DuzenlemeSaati,FontFactory.getFont(FontFactory.COURIER,9)));
cell1.setLeading(16f, 0f);
cell3.setLeading(16f, 0f);
cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(""));
cell2 = new PdfPCell(new Paragraph(""));
cell3 = new PdfPCell(new Paragraph(DuzenlemeTarihi,FontFactory.getFont(FontFactory.COURIER,9)));
cell3.setLeading(16f, 0f);
cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(" "));
cell2 = new PdfPCell(new Paragraph(" "));
cell3 = new PdfPCell(new Paragraph(" "));
cell1.setLeading(45f, 0f);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(izahat,FontFactory.getFont(FontFactory.COURIER,9)));
cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
cell1.setColspan(3);
cell1.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
cell1 = new PdfPCell(new Paragraph(" "));
cell2 = new PdfPCell(new Paragraph(" "));
cell3 = new PdfPCell(new Paragraph(" "));
cell1.setLeading(75f, 0f);
cell1.setBorder(Rectangle.NO_BORDER);
cell2.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell2);
table.addCell(cell3);
cell1 = new PdfPCell(new Paragraph(kopyayazi,FontFactory.getFont(FontFactory.COURIER,9)));
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
cell1.setColspan(3);
cell1.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
cell1 = new PdfPCell(new Paragraph(TutarYazi,FontFactory.getFont(FontFactory.COURIER,9)));
cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
cell1.setColspan(2);
cell3 = new PdfPCell(new Paragraph(ToplamTutar,FontFactory.getFont(FontFactory.COURIER,9)));
cell3.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell1.setLeading(16f, 0f);
cell3.setLeading(16f, 0f);
cell1.setBorder(Rectangle.NO_BORDER);
cell3.setBorder(Rectangle.NO_BORDER);
table.addCell(cell1);
table.addCell(cell3);
document.add(table);
document.newPage();
} catch (DocumentException de) {
de.printStackTrace();
System.err.println("document: " + de.getMessage());
}
document.close();
那么,当页面上的字符已经打印出来时,如何将点阵打印机与连续纸张一起使用,并停止纸张滚动
共 (0) 个答案