Printing document from JTextPane???

Surely it can't be that difficult, but I've tried everything, copied code from http://www.manning.com/Robinson/chapter22.pdf, nothing seems to work. I've finally got to a stage where I can print a blank page, but that's not quite what I'm after.
Any clues, hints?
My source:
=======================================
** Class extends JTextPane,
public void initialize() {
     // this method called from the constructor
     setName("JTextPane1");
     setBounds(0, 0, 6, 22);
     // user code begin {1}
     try {
     String s = "file:"
                         + "C:\\Esd\\Docs" // System.getProperty("user.dir")
                         + System.getProperty("file.separator")
                         + "PrintInvoice.html";
     java.net.URL printInvoiceURL = new java.net.URL(s);
          javax.swing.text.html.HTMLEditorKit htmlKit =
               new javax.swing.text.html.HTMLEditorKit();
          setEditorKit(htmlKit);
               /* ... use the URL to initialize the editor pane ... */
          setPage(printInvoiceURL);
          setEditable(false);
          // user code end
     } catch (java.lang.Throwable ivjExc) {
          // user code begin {2}
          // user code end
          handleException(ivjExc);
public int print(java.awt.Graphics pg, PageFormat pageFormat, int pageIndex)
     throws PrinterException {
//     PrintView m_printView =null;
     pg.translate((int)pageFormat.getImageableX(),     
          (int)pageFormat.getImageableY());
     int wPage = (int)pageFormat.getImageableWidth();
     int hPage = (int)pageFormat.getImageableHeight();
     pg.setClip(0,0,wPage,hPage);
     // do this once per print
     if (m_printView == null) {
          BasicTextUI btui = (BasicTextUI)this.getUI();
          View root = btui.getRootView(this);
          System.out.println("root element: " + this.getDocument().getDefaultRootElement());
          System.out.println("root: " + root);
          System.out.println("wPage, hPage : " + wPage + ", " + hPage);
          m_printView = new PrintView(this.getDocument().getDefaultRootElement(),
               root, wPage, hPage);
     boolean bContinue = m_printView.paintPage(pg, hPage, pageIndex);
     System.gc();
     if (bContinue)
          return PAGE_EXISTS;
     else {
          m_printView = null;
          return NO_SUCH_PAGE;
*** class PrintView extends BoxView has method paintPage
public boolean paintPage(Graphics g, int hPage, int pageIndex) {
     if (pageIndex > m_pageIndex) {
          m_firstOnPage = m_lastOnPage + 1;
          if (m_firstOnPage >= getViewCount())
               return true;//               return false;
          m_pageIndex = pageIndex;
     int yMin = getOffset(Y_AXIS, m_firstOnPage);
     int yMax = yMin + hPage;
     Rectangle rc = new Rectangle();
     for (int k = m_firstOnPage; k < getViewCount(); k++) {
          rc.x = getOffset(X_AXIS, k);
          rc.y = getOffset(Y_AXIS, k);
          rc.width = getSpan(X_AXIS, k);
          rc.height = getSpan(Y_AXIS, k);
          if (rc.y+rc.height > yMax)
               break;
          m_lastOnPage = k;
          rc.y -= yMin;
          if (k == 1)
          ; // if I call paintChild here I get null reference exception
          else
                    paintChild(g, rc, k);
     return true;
*** Dialog window that tries to print the JTextPane:
public void jButtonPrint_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
Thread runner = new Thread () {
     public void run() {
//          new PrintView (PrintInvoiceDialog.this.getJTextPane1().getDocument().getDefaultRootElement(), 1);
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(getJTextPane1());
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
runner.start();
public PrintInvoiceTextPane getJTextPane1() {
     if (ivjJEditorPane1 == null)
          ivjJEditorPane1 = new PrintInvoiceTextPane ();
return ivjJEditorPane1 ;

I have exerienced the same problem and in my seaching i found this
http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/render.html#what
It helped me greatly =)
Hope that helps

Similar Messages

  • I am having trouble printing a PDF document. Whenever I click print nothing happens but when I am printing documents from Word, Excel etc they print without a problem. I've tried printing as image but that did not work. I uninstalled Adobe Reader XI and d

    I am having trouble printing a PDF document. Whenever I click print nothing happens but when I am printing documents from Word, Excel etc they print without a problem. I've tried printing as image but that did not work. I uninstalled Adobe Reader XI and downloaded Adobe Reader X instead and that still doesn't work. I have Windows 7.

    Hello,
    Please follow the link to troubleshoot the printing issues with Adobe Reader:- Troubleshoot PDF printing | Acrobat, Reader.
    Regards,
    Nakul

  • Save/Print document from DMS with Office 365

    Dear All,
    We are on ECC 6.0 EHP 4 of SAP. When a word document attachment is opened in DMS (CV03N) from a PC having locally installed Office 365. The document is opening up in office 365 interface inside SAP. Which is good, but we are unable to save the document on to local PC. Upon clicking the File menu, i suppose word tries to bring an additional view instead of a drop down, which was the case with earlier versions. I think this is causing the problem. Can any one suggest how to save and print documents from DMS with locally installed Office 365.?
    We have figured out a work around to bring up the 'Save As' and 'Print' functionalities on to quick access tool bar. Using these shortcuts we are able to save the document but not print.
    Thank you.
    Regards,
    Kartik

    Dear Ms. Mohanapriya,
    We are quite happy with the existing DMS and our intention is not to change the existing architecture. Well, now we are able to open the document and have a workaround to save to local PC. And once the document is saved to PC users are able to print.
    Now we are looking for a solution to enable file menu of Office 365 within OLE container of SAP.
    Regards,
    Kartik

  • Print documents from a website

    I have a Mac 10.7.4.  I downloaded Adobe Reader X (10.1.3) but I cannot see or print documents from any website.  What have I done wrong?

    No screenshot (don't know how to do that)  but I have firefox open with several tabs showing.  One of the tabs is the website to download application form for a passport. When I press the link to down load the form a new tab opens but it is blank.  I have tried on a few different sites now and it is always the same - press link, new tab opens but it is blank.
    Thanks for taking the time to help me.

  • How do I get my Kodak ESP 3.2s printer to print documents from my iPad ?

    I have an iPad
    I have a Kodak ESP 3.2s all in one printer
    I have set it up to print via my home wi fi using my normal laptop with Microsoft
    However I couldn't  work out how to print from my iPad as its not configured for Apple!
    I downloaded Kodak Pic flick HD app
    This means I can now print photos from my iPad!  Great
    But still can't print documents it seems     I get a message saying No AirPrint Printers Found
    Any advice very welcome
    Thank you
    iknow0

    Airprint is a technology created by Apple Inc. and introduced in iOS 4.0 that allowed iPads, iPhones, and iPod Touches to print directly to Airprint compatible printers. Unlike computer printing where the drivers, fonts, etc. are stored on the computer and sent to the printer with the document with Airprint fonts, drivers, etc. are stored on the printer and need not be sent with the document.
    The solution to your problem is 3rd party software which both Jim and I suggested to you.

  • My HP officejet 6210 no longer prints documents from my Mac ibook G4 running 10.4.11; starts to process the document, but then stops the print,if I restart print same thing happens

    My ibookG4, running 10.4.11 suddenly decided it no longer wants to print documents thru my HP officejet 6210 all-in-one printer.  So far I've tried emails, excel and word all with the same result.  The computer will start to process the print request (processing seems to take longer than previously) and then suddenly the processing stops and a red exclamation mark appears next to the printer image at the bottom of screen.  When I pull up the printer utility it tells me the printer is "stopped".  If I restart it, the process begins all over again until once again it stops.  I have already deleted the printer completely from my computer and reinstalled the software fom the HP site.  For some reason had a really tough time finding the correct print drivers on the HP site, but did finally locate them.  I have not even attempted scanning during this (I see lots of people reported issues with that for the 6210), I would be happy if I could at least print again.  I am connecting via USB.  Is there some way to fix this?

    Hi Evelyn,
    Mac OS X: About the Reset Printing System feature ...
    http://support.apple.com/kb/HT1341?viewlocale=en_US

  • Won't let me print documents from website link

    For this specific website, when I try to print a document it will automatically download it for me but it won't print. I will click on the download and it will open up on Word, but since it is coded it will not show properly. How can I get it to print directly from the print link on the website? I've tried resetting it and it still won't print.

    [[Fix printing problems in Firefox]] may help, but if it also happens in other browsers you may want to ask the site developer.

  • Garbage text prints when printing documents from InDesign

    I am encountering an odd error when printing from InDesign 4.0.4 (CS2) to some HP printers (HP 4650 and 2430n). Some documents print just fine with no problems. But a couple of documents will either never print, or when they do print, they print a line or few of garbage text (black diamonds, smiley faces, etc.) per page, plus some blank pages, and it will run through tons of paper when it does this.
    I've found the following document which describes my problem pretty closely.
    http://h10025.www1.hp.com/ewfrf/wc/genericDocument? docname=c00028613&cc=us&dlc=en&lc=en&jumpid=regR1002USEN
    The problem is that I have set the Graphics to print as ASCII, and this problem still occurs. Could it be a problem with a particular EPS file printing or something? This document (with all of the included text, EPS images, etc) become fairly sizeable, such as 150 MB in size. The HP 4650 has 512 MB of memory, whereas the HP 2430 has 64 MB of memory.
    I printed this same problem document from another computer, with all of the same settings in InDesign, and it printed with no problems.
    Any idea on what is going on here?

    Hello Chad,
    Do you know if the two printers support PostScript? It sounds like they don't and therefore they will be using filters to convert the PS data from InDesign into a format that it understood by the printer. It will be in this conversion process that something will be going astray and that will cause the corrupted output. Try running a Repair Disk Permissions to see if this helps.
    I don't believe the amount of RAM will cause the problem, it should only impact the speed at which the document can be spooled from the Mac. However, if the error is only occuring from InDesign and when working with large files, then it may have something to do with it. But if the other PC is okay then it may rule out the RAM. What print language is the other PC using to print to the HP's?
    Regards,
    Paul

  • HP Deskjet2540 - only part prints documents from internet then gives up

    I have recently installed a HP Deskjet 2540 All-in-One Series Printer on my home network. If I print from Word or Excel it is perfect. If I try to print a 2 page document from a website (eg a hotel I'm considering for a holiday), my printer prints about a quarter of one page and then gives up. and ejects that page. I don't understand what's wrong or how to get help from HP

    Hi @GeoffR1 ,
    I see that you are having issues printing the full pages from the internet. I would like to help you out today.
    I would try another browser to see if you have the same results.  (Chrome, Firefox, Safari, Internet Explorer)
    What web browser are you using?
    With most web sites with loads of ads, pictures, banners and other assorted content in addition to the actual text of each page, printing out a web page can be difficult. Printers don't always print multi-item pages correctly.  Some sites offer a "print this page" option. It could be the format of the website also, that won't allow specific content to be printed.
    You could always copy and paste individual paragraphs from the web browser into Word or Notepad and print from there. Not the best resolution, but it will do in a crisis.
    Here is a website called www.printwhatyoulike.com and on the home page, enter the address of the page that you want to print. You can now click around the loaded web page and highlight, or delete altogether, individual components on the page. Then select print.
    Have a great weekend!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Printing documents from DIR.

    My client wants to develop report which will give documents attached to materials in BOM and documents attached to BOM as document item.
    I have given logic for fetching data and i got path also where original document is residing.
    There is requirement from client that in report if he select one row or Multiple rows which is having document number and press print button then it should print that document.
    How to achieve this?
    Is there is any functional module which will print document after giving orginal path of document?

    Hi mayuresh,
    I have some doubts abaout your requirement.
    The documents you are talking about: If they are SAP standard texts, you will never have a path bjut rather a text ID, LANGUAGE and NAME. Print them using function PRINT_TEXT.
    If your texts are stored in dome format (?) ind some path (?), please say:
    What is the format of the text(ASCII, RTF, WORD, HTML) or what?
    Is the text stored in a local directory that can be accessed only from your clients SAPGUI or is it a server directory that can be accessed only by the server?
    It is never wrong to give some details.
    Regards,
    Clemens

  • Printing documents from submitted forms

    How do you print documents that were submitted as part of the form?

    I am guessing you want to print the documents that were added to the form as "attachments".  To print the attachments select the attachment from the response in the "View Responses" tab and click the down arrow to bring up the menu.  Click "Download" to save the attachment and open it in whichever application is right for the type of file you need to print and print from there.
    Thanks,
    Josh

  • Printing documents from websites

    i wish to download Court documents from web, these are public. In firefox the first page only is printed, may of these documents have 10s of pages. This is not a problem in Explorer.
    == This happened ==
    Every time Firefox opened
    == Always

    If you are viewing a PDF document in you browser, Save/Save As the file to you Mac & then open it in Acrobat or Preview & then print.
     Cheers, Tom

  • How can I print documents from my MAC or iPad selecting page Sizing and Handling?

    How can I print a document from my MAC or Ipad selecting page Sizing and Handling?

    How to Print from Your iPad: Summary of Printer and Printing Options
    http://ipadacademy.com/2012/03/how-to-print-from-your-ipad-summary-of-printer-an d-printing-options
    Print from iPad / iPhone without AirPrint
    http://ipadhelp.com/ipad-help/print-from-ipad-iphone-without-airprint/
    How to Enable AirPrint on a Mac and Use Any Printer
    http://ipadhelp.com/ipad-help/how-to-use-airprint-with-any-printer/
    iPad Power: How to Print
    http://www.macworld.com/article/1160312/ipad_printing.html
    Check out these print apps for the iPad.
    Print Utility for iPad  ($3.99) http://itunes.apple.com/us/app/print-utility-for-ipad/id422858586?mt=8
    Print Agent Pro for iPad ($5.99)  http://itunes.apple.com/us/app/print-agent-pro-for-ipad/id421782942?mt=8   Print Agent Pro can print to many non-AirPrint and non-wireless printers on your network, even if they are only connected to a Mac or PC via USB.
    FingerPrint turns any printer into an AirPrint printer
    http://reviews.cnet.com/8301-19512_7-57368414-233/fingerprint-turns-any-printer- into-an-airprint-printer/
     Cheers, Tom

  • A website called Undertone keeps popping up and blocking my attempts to print documents from other websites

    I was trying to save a document from Town hall but a page from a website called Undertone keeps popping up and blocking mt browsing.

    If that Undertone pops up when you try to Print from Firefox: <br />
    Open the Firefox SafeMode. <br />
    [http://support.mozilla.com/en-US/kb/Safe+Mode] <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If that doesn't happen while in the Firefox SafeMode, see this: <br />
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]
    If it just pops up when viewing web pages, you may have picked up some Malware. <br />
    Install, update, and run these programs in this order. '''''(Not all programs detect the same Malware.)''''' They are all free for personal use, but some have limited functionality in the "free mode" - but those are features you really don't need to find and remove the problem that you have.<br />
    ''Note: If your Malware infection is bad enough and you are mis-directed to URL's other than what is posted, you may have to use a different PC to download these programs and use a USB stick to transfer them to the afflicted PC.''
    Malwarebytes' Anti-Malware - [http://www.malwarebytes.org/mbam.php] <br />
    SuperAntispyware - [http://www.superantispyware.com/] <br />
    AdAware - [http://www.lavasoftusa.com/software/adaware/] <br />
    Spybot Search & Destroy - [http://www.safer-networking.org/en/index.html] <br />
    Windows Defender: Home Page - [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx]
    If these don't find it or can't clear it, post in one of these forums for specialized malware removal help: <br />
    [http://www.spywarewarrior.com/index.php] <br />
    [http://forum.aumha.org/] <br />
    [http://www.spywareinfoforum.com/] <br />
    [http://bleepingcomputer.com]

  • Can't print documents from ipages

    I have been using an HP c4500 photosmart printer for months with no problems and one day it just stopped printing. It prints web pages but no documents from iPages. What happened?

    May you check if it's really this printer which is called when you try to print with Pages (there is no iPages application) ?
    Yvan KOENIG (VALLAURIS, France) vendredi 2 octobre 2009 18:37:54

Maybe you are looking for

  • MOH and Media Bypass no longer working after Skype Business updates

    Not using the Skype Business skin but still using the Lync Enterprise 2013 skin 1 - MOH still works ok with call park but not for basic Lync to Lync calls or Lync to PSTN calls. Basically I noticed that CsClientPolicy EnableClientMusicOnHold was now

  • Mac Pro will not start up. Firmware or graphics problem?

    A really weird thing happened to my MacPro 1,1. It has been working fine for the last 5 years until today when I was running Parallels and suddenly the screen got those thin, horizontal, wavy, purple lines all over the place and cursor turned into a

  • Mini Bridge crashes Bridge... Any suggestions?

    Hi, I am hoping for some help with this please. Individually, my Photoshop cs5 and Bridge work just fine, but when in I try to use Mini Bridge within Photoshop, it crashes Bridge immediately. I get this error message: These are the Problem Details: P

  • Stock Report in Sap ecc6

    Dear Team, I was previously using Russian J3RFLVMOBVED in Sap ecc6. It was working fine for the last two years for stock valuation quantity & Value wise. From Jan 2012 this report is showing Negative Stock  in the report.  For this i consulted ABAP f

  • Monitor and record server performance

    Hi all. This is not really Arch related but a general question. I have a web server that has services crashing. I think it may be due to low mem. Is there any software or some method that would allow me to monitor/log server stats/performance and the