Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box b

Discussion in 'Java' started by keto, May 30, 2007.

  1. keto

    keto Guest

    # application server - JbossServer-4.0.4.
    # OS: windowsXP
    # IDE: Eclipse
    # Problem - I want to print Current Output of Pdf file and should
    print once.I get print dialog box but it is not working
    properly.


    public void doPost(HttpServletRequest request, HttpServletResponse
    response)
    throws ServletException, IOException {

    String strId="QI0001";
    ByteArrayOutputStream baosPDF = generatePDFDocumentBytes(strId);
    response.setContentType("application/pdf");
    response.setContentLength(baosPDF.size());
    ServletOutputStream out = response.getOutputStream();
    baosPDF.writeTo(out);
    out.flush();
    try {
    if (showPrintDialog){
    if (printJob.printDialog()){
    printJob.print();
    }
    }
    } catch (Exception PrintException) {
    PrintException.printStackTrace();
    }
    protected ByteArrayOutputStream generatePDFDocumentBytes(String
    strId )
    throws DocumentException{

    Document doc = new Document(PageSize.A4, 60, 30, 80, 50);
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter=PdfWriter.getInstance(doc, baosPDF);
    docWriter.setViewerPreferences( PdfWriter.HideMenubar |
    PdfWriter.HideToolbar | PdfWriter.HideWindowUI );
    Graphic grx = new Graphic();
    grx.setHorizontalLine(0f, 100f);
    doc.open();
    doc.add(---some tables---);
    doc.close();
    return baosPDF;
    }
     
    keto, May 30, 2007
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bienwell
    Replies:
    5
    Views:
    5,425
    bienwell
    Aug 13, 2006
  2. The One
    Replies:
    5
    Views:
    719
    Steve W. Jackson
    Nov 29, 2006
  3. vasudevram
    Replies:
    0
    Views:
    546
    vasudevram
    Oct 27, 2006
  4. Shalom
    Replies:
    3
    Views:
    337
    s_m_b
    May 29, 2008
  5. Ricardo Pog
    Replies:
    1
    Views:
    792
    Austin Ziegler
    Mar 26, 2008
  6. Matt
    Replies:
    1
    Views:
    498
    Randy Webb
    Nov 20, 2004
  7. Replies:
    4
    Views:
    376
    Ted Zlatanov
    Sep 13, 2006
  8. Appu
    Replies:
    1
    Views:
    618
    Randy Webb
    Jun 19, 2006
Loading...