Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. class BillPrint implements ActionListener, Printable
  2. {
  3. PrintMngt PM=new PrintMngt();
  4. public int print(Graphics gx, PageFormat pf, int page) throws PrinterException {
  5. if (page>0){return NO_SUCH_PAGE;}
  6.  
  7.  
  8.  
  9.  
  10. Graphics2D g = (Graphics2D)gx; //Cast to Graphics2D object
  11. g.translate(pf.getImageableX(), pf.getImageableY());
  12.  
  13.  
  14. Vector<Vector<Object>> data =PM.getvarientDetail(printID);
  15.  
  16. for (int i = 0; i <data.size(); i++) {
  17. if(data.get(i).get(3).toString().equalsIgnoreCase("DYNAMIC"))
  18. {
  19. String bill_no=textField_Trans.getText();
  20. int TblH,TblL;
  21.  
  22. Vector<String> Tbl_HL=PM.getTblHieghtNoLline(printID);
  23. //PRINT_ID0, QUERY_STATIC1, OBJECT_NAME2, QUERY_TYPE3, X4, Y5, WIDTH6,
  24. //ALIGN7, FONT8, F_SIZE9, F_STYLE10, SECTION11, LOOPES_NO12, OBJ_FORMAT13, VARIANT_ID14
  25. TblH=Integer.parseInt(Tbl_HL.get(0).toString());
  26. TblL=Integer.parseInt(Tbl_HL.get(1).toString());
  27.  
  28. int x=Integer.parseInt(data.get(i).get(4).toString());
  29. int y=Integer.parseInt(data.get(i).get(5).toString());
  30. String fName=data.get(i).get(8).toString();
  31. int fSize=Integer.parseInt(data.get(i).get(9).toString());
  32. String fStyle=data.get(i).get(10).toString();
  33. Font font=null;
  34. if(fStyle.equalsIgnoreCase("Plain"))
  35. {
  36. font = new Font(fName,Font.PLAIN, fSize);
  37. }
  38. else if(fStyle.equalsIgnoreCase("Bold"))
  39. {
  40. font = new Font(fName,Font.BOLD, fSize);
  41. }
  42. else if(fStyle.equalsIgnoreCase("Italic"))
  43. {
  44. font = new Font(fName,Font.ITALIC, fSize);
  45. }
  46. else if(fStyle.equalsIgnoreCase("Bold Italic"))
  47. {
  48. font = new Font(fName,Font.BOLD+ Font.ITALIC, fSize);
  49. }
  50. System.out.println("Myqry"+data.get(i).get(1).toString());
  51. Vector<String> Query_Static=PM.getQuery_Static(data.get(i).get(1).toString(),bill_no);
  52. for (int j = NoOfProd; j < Query_Static.size(); j++) {
  53. g.drawString(Query_Static.get(j).toString(),x,y);
  54. y=y+TblH/TblL;
  55. g.setFont(font);
  56.  
  57. }
  58.  
  59. }
  60. }
  61. return PAGE_EXISTS; //Page exists (offsets start at zero!)
  62. }
  63.  
  64. public void actionPerformed(ActionEvent e) {
  65.  
  66. PrinterJob job = PrinterJob.getPrinterJob();
  67. job.setPrintable(this);
  68. boolean ok = job.printDialog();
  69. if (ok) {
  70. try {
  71.  
  72.  
  73. int ProductCnt= PM.getNoProduct(textField_Trans.getText().toString());//no. of products under given billno
  74. int TableLine=PM.getTblNoLline(printID);//no. of lines to print
  75. System.out.println("No of TableLines="+TableLine);
  76. System.out.println("No of Product="+ProductCnt);
  77.  
  78. for (int i = 0; i <(TableLine/ProductCnt); i++)
  79. {
  80. job.print();
  81. NoOfProd=NoOfProd+TableLine;
  82. }
  83. NoOfProd=0;
  84.  
  85. } catch (PrinterException ex) {
  86. ex.printStackTrace();
  87.  
  88. }
  89. }
  90. }//end actionPerformed
  91. }//end BillPrint
  92.  
  93. private void printData(){
  94. File output = new File("E:\PrintFile1.txt");
  95. output.setWritable(true);
  96. String billNo="B1000", patient = "ABC";
  97. try
  98. {
  99. BufferedWriter out = new BufferedWriter(new FileWriter(output));
  100. out.write(billNo + "n");
  101. out.write(patient + "n" );
  102. out.write("n");
  103. out.write("n");
  104. out.close();
  105.  
  106. }
  107. catch (java.io.IOException e)
  108. {
  109. System.out.println("Failed to write Output");
  110. }
  111.  
  112.  
  113. FileInputStream textStream = null;
  114. try
  115. {
  116. textStream = new FileInputStream("E:\PrintFile1.txt");
  117. }
  118. catch (java.io.FileNotFoundException e)
  119. {
  120. System.out.println("Error trying to find the print file.");
  121. }
  122.  
  123. DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
  124. Doc mydoc = new SimpleDoc(textStream, flavor, null);
  125.  
  126. PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
  127. DocPrintJob printJob = printer.createPrintJob();
  128. try
  129. {
  130. printJob.print(mydoc, null);
  131. }
  132. catch (javax.print.PrintException e)
  133. {
  134. JOptionPane.showMessageDialog(this, "Error occured while attempting to print.", "Error!", JOptionPane.ERROR_MESSAGE);
  135. }
  136. }
  137.  
  138. String numero = "Numero Nro :";
  139.  
  140. public Print() {
  141. super();
  142. }
  143.  
  144. Font textFont = new Font(Font.SANS_SERIF,Font.PLAIN,8);
  145.  
  146. g.setFont(textFont);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement