Smart form printing issue with LOCL printer and SAP printer

Hi,
The issues are as follows:
1. the top portion of the Invoice and PO does not print when using the SAP printer (works when using LOCL)
2. the shaded areas of the Order Confirmation and Invoice are black when printing to a SAP printer (works when using LOCL)
In an attempt to correct the printing issue is was suggested that we change the SAP printer device type from HPLJ4 to POST2. This did address the problem where the shaded areas were black but then we received reports that other reports printed "garbage". Its possible that using POST2 device type causes issues when printing to HP compatible printers.
Apparently all the testing was done using the SAP printer LOCL and not the SAP printer name and SAP spool system. LOCL uses the SAP GUI and Windows system to produce the output. Our production users at the plant site and Toledo are using SAP defined printers with the device type of HPLJ4. HPLJ4 is our standard here as OC for our printer definitions and we have HP compatible printers installed in our Toledo location and all of our remote sites. We need to be able to correctly print the Invoices, Purchase Orders, Sales Order Confirmations on our SAP printers.
What can be done to the reports to allow them to print on our HPLJ4?
Thanks,
Babu

Hi Prathap,
Check the background shading of the windows of the Smartform where you get the black boxes. If it is set something like this:
Color: White
Saturation: 100%
this can be the problem.
I know it is strange but some black and white printers cannot handle this setting. They only know one color black so the ignore the color setting and just take the saturation 100% setting.
The reason it works with local and device type SAPWIN is that the print data is created in Windows and sent to the printer as graphic.
Please change the shading for window MAIN -> tab 'Output Options' to:
Color: Black
Saturation: 0%
and this should resolve the problem.
Then create a new spool and check if the problem is resolved. See SAP Note #400050.
Regards,
Prabhu

Similar Messages

  • Smart form printing issue with LOCL and SAP printer

    Hi,
    The issues are as follows:
    1. the top portion of the Invoice and PO does not print when using the SAP printer (works when using LOCL)
    2. the shaded areas of the Order Confirmation and Invoice are black when printing to a SAP printer (works when using LOCL)
    In an attempt to correct the printing issue is was suggested that we change the SAP printer device type from HPLJ4 to POST2. This did address the problem where the shaded areas were black but then we received reports that other reports printed "garbage". Its possible that using POST2 device type causes issues when printing to HP compatible printers.
    Apparently all the testing was done using the SAP printer LOCL and not the SAP printer name and SAP spool system. LOCL uses the SAP GUI and Windows system to produce the output. Our production users at the plant site and Toledo are using SAP defined printers with the device type of HPLJ4. HPLJ4 is our standard here as OC for our printer definitions and we have HP compatible printers installed in our Toledo location and all of our remote sites. We need to be able to correctly print the Invoices, Purchase Orders, Sales Order Confirmations on our SAP printers.
    What can be done to the reports to allow them to print on our HPLJ4?
    Thanks, Prathap

    Hi Prathap,
    Check the background shading of the windows of the Smartform where you get the black boxes. If it is set something like this:
       Color: White
       Saturation: 100%
    this can be the problem.
    I know it is strange but some black and white printers cannot handle this setting. They only know one color black so the ignore the color setting and just take the saturation 100% setting.
    The reason it works with local and device type SAPWIN is that the print data is created in Windows and sent to the printer as graphic.
    Please change the shading for window MAIN -> tab 'Output Options' to:
       Color: Black
       Saturation: 0%
    and this should resolve the problem.
    Then create a new spool and check if the problem is resolved. See SAP Note #400050.
    Regards,
    Aidan

  • Printing Issues with HP D145 and multiple users from G5

    Hi - I've a HP D145 All-In-One connected via USB to a G5 (as described below). The machine has multiple accounts on for different members of my family. The printer is directly connected to the G5 via USB connection but is shared with other Macs. Printing has become increasingly difficult, and we now have the following problems:
    1. Printing will only work from the administrators account.
    2. Printing periodically (daily, generally after a few hours of use) stops from the administrators account
    Solutions tried:
    a. Check set up for the non-administrators accounts....Looks OK for printing
    b. When printing stops - I've tried repairing the permissions with the Disk Utility. This no longer works.
    c. Run Printer Setup Repair (with option to repair all user accounts) - Works for the administrators account providing the computer and printer are restarted, otherwise no effect.
    d. Reinstalling the software - No effect
    It’s beginning to look like I need to replace this printer with one that works.
    You can help me in two ways - how to solve the printer problems, or alternatively suggest a colour All-in-One printer that can work with multiple accounts and does not have the problems mentioned above.
    Many thanks in advance,
    Regards,
    Melvyn

    Below I've copied the fix HP proposed and some additional information that they have sent me.
    1. The proposed fix that we could not make work:
    Hello Melvyn,
    Thank you for contacting HP Total Care.
    Simply reinstalling the software will not be enough to solve the
    problem. Try these steps to resolve the issue at hand:
    From the Administrator account:
    Double-click on the Macintosh Hard Disk.
    Open Applications.
    Click and drag Hewlett Packard Folder to the trash.
    Close all windows.
    Double-click on the Macintosh Hard Disk.
    Open the Applications folder.
    Open the Utilities folder.
    Double-click on Process Viewer/Activity Monitor
    If Activity Monitor does not appear:
    Choose Monitor in the toolbar across the top.
    Check Show Activity Monitor.
    Ensure the Activity Monitor shows "All Processes", instead of "My
    Processes".
    Single-click and quit each of the applications starting with HP, using
    the Stop Sign that says "Quit Process" beneath it.
    Close Activity Monitor.
    Double-click Macintosh Hard Disk.
    Open the Library folder.
    Open the Preferences folder.
    Click and drag either HP AIO Preferences or Hewlett Packard Preferences
    to the trash.
    Remove the HP Registry file.
    Go back to the Library folder.
    Open the Printers folder.
    Remove the HP folder
    Double click Macintosh Hard Disk.
    Open the Users folder.
    Choose the User logged into.
    Open the Library folder.
    Open the Preferences folder.
    Click and drag either HP AIO Preferences or Hewlett Packard Preferences
    to the trash.
    Click and drag files beginning with com.hp to the trash.
    Click and drag files beginning with HP to the trash.
    Double-click the Macintosh Hard Disk.
    Open the Applications folder.
    Open the Utilities folder.
    Double-click Printer Setup Utility.
    Delete any HP All-In-One printers listed (click the printer name to
    highlight it, then click the Delete button on the printer list)
    Repeat process for all HP All-In-One Printers.
    Remove HP Director/Image Zone from dock by dragging to the trash.
    Restart the Macintosh.
    Empty the Trash.
    From each user account:
    Double click Macintosh Hard Disk.
    Open the Users folder.
    Choose the User logged into.
    Open the Library folder.
    Open the Preferences folder.
    Click and drag either HP AIO Preferences or Hewlett Packard Preferences
    to the trash.
    Click and drag files beginning with com.hp to the trash.
    Click and drag files beginning with HP to the trash.
    Double-click the Macintosh Hard Disk.
    Open the Applications folder.
    Open the Utilities folder.
    Double-click Printer Setup Utility.
    Delete any HP All-In-One printers listed (click the printer name to
    highlight it, then click the Delete button on the printer list)
    Repeat process for all HP All-In-One Printers.
    Remove HP Director/Image Zone from dock by dragging to the trash.
    Restart the Macintosh.
    Empty the Trash.
    From the Administrator account:
    Download and install the latest software for this product. You can
    obtain this software from the following link:
    http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?lc=en&cc=us⟨=en&os=219& product=64992&dlc=en&softwareitem=oj-35225-1
    From each user account:
    Double-click the Macintosh Hard Disk.
    Open the Applications folder.
    Open the Utilities folder.
    Double-click Printer Setup Utility.
    Click Add, ensure you are in the Default Browser.
    Select the HP All-In-One Printer.
    Click Add at the bottom-right corner of the screen.
    Set this printer as the default.
    You should now be able to print from all accounts.
    Sincerely,
    2. The reasons why it may not have worked:
    We need to be sure that you are fully logging out of one account and
    then back into the next. The fast user switching feature of the Mac OS
    can create problems with our printer drivers. For this reason, fast user
    switching is not supported by HP.
    The other issue we may be running into would be the Mac OS itself. Over
    the past few months the Mac OS has gone through several updates. When
    the 10.4.4 version was released it created some issues with our existing
    software. An updated version of our software has been developed which
    works well with 10.4.4 and higher, but it is not available for this
    printer.
    It may be that as each new OS update is installed on your computers that
    the issue becomes worse. If you are running the Mac OS 10.4.3 or lower
    then the version 7.3.1 of our software should work fine. If it is 10.4.4
    or higher there will be some issues as the new OS versions do not seem
    to like the older drivers.
    I would have to recommend retrying the full uninstall the Derek had
    outlined. This time however, just install the downloaded 7.3.1 software
    from our web site for the D145. Once it has been installed we need to
    test it fully without adding the scanjet software. I am hoping that
    without both version of our software installed it may work better.
    This should resolve the issue. If you need further assistance, please
    reply to this message and we will be happy to assist you further.
    3. The repsonse to questions on switching and OS X 10.4.4
    You are correct, since you are running the 10.4.4 I cannot guarantee
    that the older software version will allow full functionality. It should
    allow for printing and as long as you avoid the fast user switching,
    when trying to print, it should keep working well.
    I understand the convenience of fast user switching but you will have to
    log completely out of one user, and then log properly into the next
    before you can expect the printer to function.
    I would still recommend trying the steps I had outlined as it really is
    the only thing you can do that may work.
    G5, 2 GHz dual processor, 2Gb RAM, 500GB Hard disk   Mac OS X (10.4.3)   Clarification of the issues from HP

  • Print issue with Photoshop CS4 and Officejet 6500

    I have a Windows 7 Business 64 bits desktop computer. After  installing the Officejet Pro 6500 multifunctional drivers all was  working OK. Images were being printed nice and with the correct size  using Windows print option. After installing Adobe CS4 suite, all images  printed from windows or Photoshop have incorrect size (photoshop prints  it smaller, about 33%, and on upper left corner of the sheet).
    Photoshop sucks but Illustrator print fine. The only way I can print  at the good size in Photoshop, it's when I select Microsoft XPS  document writer as printer and print from there... Not very user friendly !!!
    And  yes, it was always the HP Officejet 6500 E709n fax selected by default  by Photoshop instead of  HP Officejet 6500 E709n !
    Is anybody can say if it's an HP issue or an Adobe issue ??? Why Illustrator print fine and Photoshop don't ???
    Thank's  in advance.

    Deleting the fax printer  associated with this device to allows correct printing is not an  acceptable alternative for me.
    If it is a printer issue, why I can print correctly from Illustrator ???
    dec9 wrote:
     Or: you can go into windows and select a default printer or then the one you use to print with in PS. Then when you are ready to print in PS select the printer. See if that works.
    That's my normal configuration then I can't change nothing when all is ok.
    Thank you very much for your answer ! Maybe anybody have an other solution or explanation.
    Thank's for your patience.

  • Printer issue with 10.6 and Dell All in One 968W

    The Dell All in One 968W is basically a Lexmark 9500 series with a Dell badge. Dell do not support OSX but Lexmark have previously supplied a driver that works and allows me to print on the Dell printer.
    However with 10.6 OSX will no longer support the Dell printer. I have tried using the supplied Lexamrk 9500 series dirvers with no luck, and I have tried going to back to the older Lexamrk dirver. The error message suggests that I need to get an updated driver from Lexmark. Lexamark do no yet provide this.
    Has anyone found a solution to this problem?

    Hi
    Have you find any solution????
    Lexmark has a lastest driver the 9500SeriesWebInstaller1.0.1.dmg released the 09/15/09 but it doesn't detects the printer
    if we delete the default snow leopard driver for lexmark and install this new????

  • Color issues with Business Cards and Vista Print (Ps & Ai)

    So I use Vista Print for my business cards, quick, easy and affordable.
    I had some graphics that could not be reproduced in Ai very easily so I downloaded the Vista Print .PSD template and worked off of that.
    When the cards came in color was correct but the font was not good. Not very clear and there was digital noise around the edges, so not crisp.
    So I downloaded the Ai template from VP, reproduced the card in Ai and just dropped the logo in on the canvas and redid all the text in Ai.
    When I got these cards in, the font looked much better and crisp, but all my colors were off. My navy blues were not navy-purplish looking. Side by side, it was a big difference.
    I didn't change any color profiles I even made sure the CMYK values from the original photoshop file matched exactly to the Ai file.
    So question is, why would the Ai file print differently if the CMYK color values were the exact same? It makes no sense to me. Was it perhaps how I saved the Ai files? There are so many options when saving it's a bit overwhelming.

    Believe it or not, the Vista Print cards could be color copies.  Try and post a screen shot of each card so we can see the differences.  Not sure how you proofed the card redo out of Illustrator and/or what you used to print the redo card.  The problem with Vista Print is quality control.  You say the card color is accurate in the VP cards.  However, did you proof the card before sending it to VP?  If you did, how?

  • Printing issue with microsoft word and excel

    I open Microsoft 2004 Word and Excel separately and clicked on File / Open....not responding and so force quite. I went to Finder and opened the file directly and It did. But when I clicked Print, the print page doesn't show up. I closed the file. I opened other softwares and tried the Print and Save as PDF and it worked. I booted several times and reinstaled the Microsoft 2004 from original disk and did updates up to 11.6.3 versions. I rebooted again and still the same problem. Please help !

    If you applied the Security Update from a few days ago it sounds like you are affected with this problem:
    http://9to5mac.com/2012/02/03/latest-apple-updates-also-messing-with-rosetta-pow erpc-apps-like-quicken/

  • Issue with user mapping and SAP reference system

    Hello Gurus,
    I have this strange system behaviour when preparing my system for single sign-on using user mapping.
    Case 1.
    In the user management property category, I have the following defined.
    Authentication Ticket Type - SAP Logon Ticket
    Logon Method - UIDPW
    User Mapping Fields  -
    User Mapping Type - admin, user
    In the alias editor, I defined the default alias as SAP_PRD
    Result= when I go to identity management to assign the reference system (the default alias - SAP_PRD)...I do not see the system alias there.
    Case 2:
    In the user management property category, I have the following defined
    Authentication Ticket Type - SAP Logon Ticket
    Logon Method - SAPLOGONTICKET
    User Mapping Fields  -
    User Mapping Type - admin, user 
    In the alias editor, I defined the default alias as SAP_DEV
    Result, when I go to the identity management to assign the refernce system (the default alias - SAP_DEV), I see it there.
    What might be my issue? Does it mean I can't assign SAP reference if I am using UIDPW as logon method?
    Please help me.

    Hi Mahesh,
    Thanks for the feedback. I am relatively new to EP...so please I won't mind if you can guide me on how to go about this.
    This is what I did...
    I chose System Administration > Permissions
    In the PCD, I located my system with the alias, SAP_PRD
    It opened up the permission assignment area.
    Now I have these permissions set
    Administrator - Full Control
    Administrators - Full control
    com.sap.caf.eu.gp.roles.superuser - Full control
    Everyone (built in group) - Full control
    Everyone (Everyone role)- Full control
    super_admin_role - Owner
    For all the above End User box is checked.
    I can't find anyone end user group .
    Once I pick UIDPW, the alias disapperars from the reference system list.
    Please help.

  • List of script and smart forms(except TNAPR) with output type or print prog

    How to find out List of SAP SCRIPT and SMART FORMS (except TNAPR)with output type or print program..I like to chk in output type WMTA  whch form should use.kindly help on this

    Hi
    WMTA is special msg and doesn't create any print: so you can't find a sapscript or smartform to link to it.
    WMTA is a message for delivery, so you can find it by NACE trx or TNAPR table (It's the same): infact here it can find only all messages of logistic modules (SD & MM).
    The routine ENTRY of RLAUTA20 is called by WMTA and creates a Transfer Order (for WM, Warehouse Management, module), so if you need to create a print for that msg you need to change prg RLAUTA20,
    Max

  • Auto adjustment of page orientation causes printing issues with documents that have a page width greater than its page height.

    Hi,
    Since an upgrade from Word 2003 to Word 2010, we are experiencing printing issues with certain
    documents that have a page width greater than its page height.
    In Word 2003, it was no problem to set the page width greater than the page height while setting the page orientation to "portrait".
    In Word 2010, this seems impossible: despite leaving the page orientation to "portrait", if one changes the page width/height as stated,
    Word 2010 automatically adjusts the orientation to "landscape". Resetting the orientation to "portrait" will flip the page's width/heigth settings.
    This behaviour causes printing problems: the page prints out 90° rotated.
    I do not believe this is a printer driver issue: I tried several different printer drivers, and all give the same (bad) result. Setting the printer driver's page orientation settings (before printing) makes no difference, as
    Word 2010 seems to force the page orientation settings.
    Inserting the documents 90° rotated is not an option, since it causes problems with the printing margins.
    This is very annoying, since we have to print official documents of a municipality (driver's licences).
    Is there a workaround for this issue?
    Regards,
    Laurent Grandgaignage
    Sysadmin Gemeentebestuur Stabroek, Belgium

    Hi
    Thank you for using
    Microsoft Office for IT Professionals Forums.
    From your description, we can follow these steps to test this issue
    Step 1: Repair Office 2010
    1.      
    Click
    Start, and then click Control Panel.
    2.      
    Click
    Programs and Features.
    3.      
    Click the
    Office 2010 program that you want to repair, and then click
    Change.
    4.      
    Click
    Repair, and then click Continue. You might need to restart your computer after the repair is complete.
    Step 2:
    Rename the global template (Normal.dotm)Follow the steps for the operating system that you are using:
    Windows Vista and Windows 7
    a)      
    Exit Word 2010
    b)      
    Click
    Start.
    c)       
    In the
    Start Search box, type the following text, and then press
    ENTER:
    1.      
    %userprofile%\appdata\roaming\microsoft\templates
    d)      
    Right-click
    Normal.dotm, and then click Rename.
    e)      
    Type
    Oldword.old, and then press ENTER.
    Microsoft Windows XP
    a)      
    Exit Word 2010
    b)      
    Click
    Start, and then click Run.
    c)       
    In the
    Open box, type the following text, and then press ENTER:
    %userprofile%\Application Data\Microsoft\Templates
    d)      
    Right-click
    Normal.dotm, and then click Rename.
    e)      
    Type
    Oldword.old, and then press ENTER.
    f)       
    Close Windows Explorer.
    How to troubleshoot print failures in Word 2010, Word 2007, and Word 2003
    http://support.microsoft.com/kb/826845
    Please take your time to try the suggestions and let me know the results at your earliest convenience. If anything is unclear or if there is anything
    I can do for you, please feel free to let me know.
    Hope that helps.
    Sincerely
    William Zhou CHNPlease remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Wireless Printing issues with HP Deskjet 2540

    Hello everyone,
    I am experiencing an issue with an HP Deskjet 2540 printer - it prints if I have connected it to a USB cable; however, it refuses to print if I try to print wirelessly. 
    I had initially solved this problem when I went to System Preferences > Printers and Scanners and noticed two Deskjet 2540 series icons in a window titled 'Printers'. I ended up removing one of these icons and set the other one as a default, which seemed to temporarily solve my problem. Now, I see two icons back in this 'Printers' menu and my printer refuses to print through my wireless connection.
    My printer is connected to my internet connection so I don't think there is an issue here - I also have recently installed the software for this printer to make sure there was not some sort of driver issue; however, this does not seem to give me the permanent solution I am looking for.
    Any Advice? My operating system is OS X Version 10.9.5

    Hey @love2dance,
    Welcome to the HP Support Forums!  I understand you're having difficulty printing wirelessly with your HP Deskjet 2540 All-in-One Printer.  I would like to assist you with this and may have some steps that will ensure you can print wirelessly from your Mac.  
    I recommend you start from scratch and re-do your printer install and wireless setup for best results. 
    Firstly, make doubly sure your printer is connected to your wireless network by doing the following:
    Step one: Prepare for installationTo gather your network name (SSID) and password (WEP key or WPA passphrase), you can ask the person who originally set up your network, see the documentation that came with the router, or contact the manufacturer. HP cannot set up or change the network SSID or the password.
    Make sure that you have the following requirements before you begin:
    Network name: The network name is the SSID (Service Set Identifier).
    WEP key or WPA security passphrase
    A computer that is connected to the wireless network.
    Internet access. HP recommends broadband Internet access such as cable or DSL.
    Your wireless-capable HP product. Place it close to the computer during the installation procedure.
    A USB cable (used only during installation).
    Administrator privileges or password
    Make sure the product, access point, and computer are all on, and that the computer is connecting to the wireless network.
    Connect the USB Cable to the rear port of the HP product and to any USB port on the computer.
    Exit all applications running on your computer.
    Source
    Secondly, prepare your Mac by removing any existing printers added:
    Choose System Preferences from the Apple menu.
    Choose Print & Scan from the View menu.
    Click the "-" (Remove printer) button.
    Next, click here to download and install your printer's software.  As you work your way through the setup, follow the prompts to convert your usb install to wireless.  With this setup completed successfully your wireless printing capability should be restored. 
    One way to preserve this wireless connection is to make sure your wireless mode/router is left on continually.  If at anytime your network connection is lost, reconnecting your printer will mean that it's being assigned a new IP address.  The significance here is that your Mac will be looking to connect with the printer at an IP address that is no longer applicable. 
    Please let me know the result of your troubleshooting by responding to this post.  Best of luck! 
    E-roq
    I work on behalf of HP.
    Please click Accept as Solution if you feel my post solved your issue, it will help others find the solution.
    Click Kudos Thumbs Up on the right to say “Thanks” for helping!

  • Issue with appletalk, can't reinstall printer, help!

    Hi all,
    Right now I'm having an issue with my older laser printer not showing up. It's installed, but when I go to print, I get a message that AppleTalk is inactive. So I go to the networking area and lo, the AppleTalk is indeed active. What is one to do now? Any suggestions?
    It was running fine previous to some issues with my modem and router, but those have been resolved. The printing won't even occur now with a direct connection, so I've kinda got lost here.
    Thanks in advance for any recommendations!
    kmack

    Hi all,
    Right now I'm having an issue with my older laser
    printer not showing up. It's installed, but when I go
    to print, I get a message that AppleTalk is inactive.
    So I go to the networking area and lo, the AppleTalk
    is indeed active. What is one to do now? Any
    suggestions?
    How are you connected to the printer? Are both of you on a wired net, or both on a wireless net? If the computer is connected via wireless, is AirPort set to do AppleTalk, or is Ethernet set to do AppleTalk? You gotta have the right one set up.
    It was running fine previous to some issues with my
    modem and router, but those have been resolved. The
    printing won't even occur now with a direct
    connection, so I've kinda got lost here.
    What kind of router do you have? Does it do AppleTalk? Are you and the printer on the same subnet? (That is, if the computer has an IP of 192.168.0.x, does the printer have an IP of 192.168.0.y, or not? If 'not', you're on different subnets and you cannot print to that printer if the router doesn't do AppleTalk.)
    Thanks in advance for any recommendations!
    kmack

  • Strange Printing Issue With New HP & Pages

    Hello!
    I have a very strange printing issue with a new HP printer. I have written pages documents heavy in Texts which are located within tables. The documents print fine on a Cannon and Epson printer and look great but when I print the document on my new HP Laserjet Pro 400 Colour M451nw some of the text on some rows come out of the printer looking like they are bold / slightly fuzzy. This only happens with some of the rows of text, not all of them. The font is the same in every row with the same format.
    You can see this in the attached image. The first line (Thanks very much) has printed correctly but the subsequent lines look bold / slightly fuzzy.
    After a lot of testing the only way I can resolve this is if I copy the content into a new pages document and only then it will print and look ok with the HP printer.
    This must be a problem within my origional document. I would simply copy and paste everything into a new document however this would take a very, very long time (over 5 years of work producing teaching materials and over 100 documents and thousands of tables and formatting that cannot be copied and pasted).
    Also, on other printers you can see the lines seperating each row of the table. These lines are not visible on the HP print outs, even when the table is copied into a new document.
    Has anyone come accross an issue like this before? Is there a way I can fix this without creating a new document? Do I need to get a new another new printer (the 4th printer this week!)?
    Any advise, wise words would be greatly apprechiated!
    Thanks!

    Sorry, Fruhulda. After 4 hours on the phone with Apple care they are taking this issue further themselves. It seems to be a problem with our pages document and the compatibility with certain drivers. We have still not gotton to the bottom of it and Apple are going to get back to me when they have an answer.
    We also worked out that the issue only happens when you print via Ethrenet & USB. Printing via Wifi is ok and there are no quality issues.
    Very Strange!

  • Can I set up multiple usb hard drives- one for time machine and a second for media? Can one also print wirelessly with an old HP C6280 printer?

    Can I set up multiple usb hard drives- one for time machine and a second for media?
    Can one also print wirelessly with an old HP C6280 printer?

    Can I set up multiple usb hard drives- one for time machine and a second for media?
    Yes.
    Can one also print wirelessly with an old HP C6280 printer?
    Possibly by using an Airport Express, but depends on what type of port connection the printer requires.

  • Print JTable with Multiple pages and rows

    I took the printing example at http://java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html#pe and modified it a bit to include the following:
    1) To Print Multiple pages
    2) To wrap lines that is too long for the column
    3) To print with a more proffesional style, so that it doesn't look like a screen capture is printed
    4) To align the numbers to the right and center column headings
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.Dimension;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import java.text.*;
    public class Report implements Printable
         private final int LEFT_ALIGN = -1;
         private final int CENTER_ALIGN = 0;
         private final int RIGHT_ALIGN = 1;
         private JFrame frame;
         private JTable tableView;
         private String lastPrintDate;
         private Font defaultFont;
         private Font headerFont;
         private Font footerFont;
         private int headerHeight;
         private int footerHeight;
         private int cellBuffer = 5;
         private boolean first_pass;
         private ArrayList pages;
         public Report()
              frame = new JFrame("Sales Report");
              frame.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent e)
                        System.exit(0);
              final String[] headers =
                   "ID",
                   "Description",
                   "open price",
                   "latest price",
                   "End Date",
                   "Quantity"
              int count = 0;
              final Object[][] data =
                   {new Integer(count++), "Box of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of BirosBox of Biros ppppppppppppppp", "1.00", "4.99", new Date(), new Integer(200000)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++), "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++), "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++), "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++), "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++), "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++),  "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++),  "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
                   {new Integer(count++),  "Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
                   {new Integer(count++),  "legal pad", "1.00", "2.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "tape", "1.00", "1.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "stapler", "4.00", "4.49", new Date(), new Integer(1)},
                   {new Integer(count++),  "Box of Biros", "1.00", "4.99", new Date(), new Integer(2)}
              TableModel dataModel = new AbstractTableModel()
                   public int getColumnCount() { return headers.length; }
                   public int getRowCount() { return data.length;}
                   public Object getValueAt(int row, int col)
                        return data[row][col];
                   public String getColumnName(int column)
                        return headers[column];
                   public Class getColumnClass(int col)
                        return getValueAt(0,col).getClass();
                   public boolean isCellEditable(int row, int col)
                        return (col==1);
                   public void setValueAt(Object aValue, int row, int column)
                        data[row][column] = aValue;
              tableView = new JTable(dataModel);
              JScrollPane scrollpane = new JScrollPane(tableView);
              scrollpane.setPreferredSize(new Dimension(500, 80));
              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(BorderLayout.CENTER,scrollpane);
              frame.pack();
              JButton printButton= new JButton();
              printButton.setText("print me!");
              frame.getContentPane().add(BorderLayout.SOUTH,printButton);
              // for faster printing turn double buffering off
              RepaintManager.currentManager(frame).setDoubleBufferingEnabled(false);
              printButton.addActionListener( new ActionListener()
                   public void actionPerformed(ActionEvent evt)
                        doPrint();
              frame.setVisible(true);
          * Reset variables before printing
         private void prepareForPrint()
              pages = new ArrayList();
              first_pass = true;
          * Display a print dialog with some hardcoded defaults
          * The print fonts are also hardcoded
         public void doPrint()
              try
                   String jobName = "Java Report";
                   defaultFont = new Font("Arial", Font.PLAIN, 8);
                   footerFont = new Font("Arial", Font.PLAIN, 6);
                   headerFont = new Font("Arial", Font.BOLD, 10);
                   PrinterJob prnJob = PrinterJob.getPrinterJob();
                   prnJob.setPrintable(this);
                   PrintRequestAttributeSet prnSet = new HashPrintRequestAttributeSet();
                   prnSet.add(new Copies(1));
                   prnSet.add(new JobName(jobName, null));
                   prnSet.add(MediaSizeName.ISO_A4);
                   PageFormat pf = prnJob.defaultPage();
                   pf.setOrientation(java.awt.print.PageFormat.PORTRAIT);
                   prnJob.setJobName(jobName);
                   PrintService[] services = PrinterJob.lookupPrintServices();
                   if (services.length > 0)
                        if (prnJob.printDialog(prnSet))
                              * Get print date
                             String dateFormat = "dd/MM/yyyy HH:mm:ss";
                             DateFormat m_DateFormat = new SimpleDateFormat(dateFormat);
                             lastPrintDate = m_DateFormat.format(new Date()).toString();
                             prepareForPrint();
                             prnJob.print(prnSet);
                   else
                        JOptionPane.showMessageDialog(frame, "No Printer was found!!", "Printer Error", JOptionPane.ERROR_MESSAGE);
                        return;
              catch (PrinterException e)
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
               * Check if this is the first time the print method is called for this print action.
               * It is not guaranteed that the print will be called with synchronous pageIndex'es,
               * so we need to calculate the number of pages and which rows appear on which pages.
               * Then the correct page will be printed regardless of which pageIndex is sent through.
              if (first_pass)
                   calcPages(g, pageFormat);
              first_pass = false;
              // Stop printing if the pageIndex is out of range
              if (pageIndex >= pages.size())
                   return NO_SUCH_PAGE;
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() + pageFormat.getImageableY();
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = pageWidth / (tableWidth+ (cellBuffer * tableView.getColumnCount()));
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)tableView.getColumnModel().getColumn(i).getWidth() * scale;
              // Reset the view to the start of the page
              g2.translate(0, 0);
              // Draw a rectangle to see the printable area
              g2.draw3DRect((int)pageFormat.getImageableX(),
                        (int)pageFormat.getImageableY(),
                        (int)pageFormat.getImageableWidth(),
                        (int)pageFormat.getImageableHeight(),
                        false);
              // Calculate the header height
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              // Print the headers and retreive the starting position for the data
              int next_row = printLine(g2, pageFormat, fontMetrics, -1, (int)pageFormat.getImageableY() + fontHeight, columnWidths);
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              // Start printing the detail
              ArrayList page = (ArrayList)pages.get(pageIndex);
              int start = ((Integer)page.get(0)).intValue();
              int end = ((Integer)page.get(1)).intValue();
              for (int i = start; i <= end; i++)
                   next_row = printLine(g2, pageFormat, fontMetrics, i, next_row, columnWidths);
              // Print the footer
              g2.setFont(footerFont);
              String pageFooter = "Page " + (pageIndex + 1) + " - " + lastPrintDate;
              g2.drawString(pageFooter,
                             (int)pageFormat.getWidth() / 2 - (fontMetrics.stringWidth(pageFooter) / 2),
                             (int)(pageHeight - fontDescent));
              return PAGE_EXISTS;
          * We can't guarantee that the same amount of rows will be displayed on each page,
          * the row heights are dynamic and may wrap onto 2 or more lines.
          * Thus we need to calculate the height of each row and then test how may rows
          * fit on a specific page. eg. Page 1 contains rows 1 to 10, Page 2 contains rows 11 to 15 etc.
         public void calcPages(Graphics g, PageFormat pageFormat) throws PrinterException
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() - fontHeight;
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = pageWidth / (tableWidth+ (cellBuffer * tableView.getColumnCount()));
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)tableView.getColumnModel().getColumn(i).getWidth() * scale;
              // Calculate the header height
              int maxHeight = 0;
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = tableView.getColumnName(j).toString();
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
              headerHeight = g2.getFontMetrics().getHeight() * maxHeight;
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              int pageNum = 0;
              int bottom_of_page = (int)(pageFormat.getImageableHeight() + pageFormat.getImageableY()) - footerHeight;
              int prev_row = 0;
              int next_row = (int)pageFormat.getImageableY() + fontHeight + headerHeight;
              int i = 0;
              ArrayList page = new ArrayList();
              page.add(new Integer(0));
              for (i = 0; i < tableView.getRowCount(); i++)
                   maxHeight = 0;
                   for (int j = 0; j < tableView.getColumnCount(); j++)
                        String value = tableView.getValueAt(i, j).toString();
                        int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                        if (numLines > maxHeight)
                             maxHeight = numLines;
                   prev_row = next_row;
                   next_row += (fontHeight * maxHeight);
                   // If we've reached the bottom of the page then set the current page's end row
                   if (next_row > bottom_of_page)
                        page.add(new Integer(i - 1));
                        pages.add(page);
                        page = new ArrayList();
                        page.add(new Integer(i));
                        pageNum++;
                        next_row = (int)pageFormat.getImageableY()
                                       + fontHeight
                                       + ((int)pageFormat.getHeight() * pageNum)
                                       + headerHeight;
                        bottom_of_page = (int)(pageFormat.getImageableHeight()
                                            + pageFormat.getImageableY())
                                            + ((int)pageFormat.getHeight() * pageNum)
                                            - footerHeight;
                        //Include the current row on the next page, because there is no space on this page
                        i--;
              page.add(new Integer(i - 1));
              pages.add(page);
          * Print the headers or a row from the table to the graphics context
          * Return the position of the row following this one
         public int printLine(Graphics2D g2,
                                       PageFormat pageFormat,
                                       FontMetrics fontMetrics,
                                       int rowNum,
                                       int next_row,
                                       double[] columnWidths)
                   throws PrinterException
              int lead = 0;
              int maxHeight = 0;
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = null;
                   int align = LEFT_ALIGN;
                   if (rowNum > -1)
                        Object obj = tableView.getValueAt(rowNum, j);
                        if (obj instanceof Number)
                             align = RIGHT_ALIGN;
                        value = obj.toString();
                   else
                        align = CENTER_ALIGN;
                        value = tableView.getColumnName(j);
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
                   if (fontMetrics.stringWidth(value) < columnWidths[j])
                        // Single line
                        int offset = 0;
                        // Work out the offset from the start of the column to display alignment correctly
                        switch (align)
                             case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                             case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                             default: offset = 0; break;
                        g2.drawString(value,
                                       lead + (int)(pageFormat.getImageableX() + offset),
                                       next_row);
                   else
                        for(int a = 0; a < numLines; a++)
                             //Multi-Line
                             int x = 0;
                             int width = 0;
                             for(x = 0; x < value.length(); x++)
                                  width += fontMetrics.charWidth(value.charAt(x));
                                  if (width > columnWidths[j])
                                       break;
                             int offset = 0;
                             // Work out the offset from the start of the column to display alignment correctly
                             switch (align)
                                  case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                                  case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                                  default: offset = 0; break;
                             g2.drawString(value.substring(0, x),
                                            lead + (int)(pageFormat.getImageableX() + offset),
                                            next_row + (fontMetrics.getHeight() * a));                    
                             value = value.substring(x);
                   lead += columnWidths[j] + cellBuffer;
              // Draw a solid line below the row
              g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                             next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent(),
                             pageFormat.getImageableY() + pageFormat.getImageableWidth(),
                             next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent()));
              // Return the position of the row following this one
              return next_row + (fontMetrics.getHeight() * maxHeight);
         public static void main(String[] args)
              new Report();
    }

    Fixed some bugs and added a title. Just pass in a JTable and the class will do the rest.
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
    import java.text.*;
    import java.math.*;
    public class PrintJTable implements Printable
         private final int LEFT_ALIGN = -1;
         private final int CENTER_ALIGN = 0;
         private final int RIGHT_ALIGN = 1;
         private JFrame m_parent;
         private String m_title;
         private JTable tableView;
         private String lastPrintDate;
         private Font defaultFont;
         private Font headerFont;
         private Font footerFont;
         private int headerHeight;
         private int footerHeight;
         private int cellBuffer = 5;
         private boolean first_pass;
         private ArrayList pages;
         public PrintJTable(JFrame parent, JTable table)
              m_parent = parent;
              tableView = table;
              doPrint();
         public PrintJTable(JFrame parent, String title, JTable table)
              m_parent = parent;
              m_title = title;
              tableView = table;
              doPrint();
          * Reset variables before printing
         private void prepareForPrint()
              pages = new ArrayList();
              first_pass = true;
          * Display a print dialog with some hardcoded defaults
          * The print fonts are also hardcoded
         public void doPrint()
              try
                   String jobName = "Java Report";
                   defaultFont = new Font("Arial", Font.PLAIN, 8);
                   footerFont = new Font("Arial", Font.PLAIN, 6);
                   headerFont = new Font("Arial", Font.BOLD, 8);
                   PrinterJob prnJob = PrinterJob.getPrinterJob();
                   prnJob.setPrintable(this);
                   PrintRequestAttributeSet prnSet = new HashPrintRequestAttributeSet();
                   prnSet.add(new Copies(1));
                   prnSet.add(new JobName(jobName, null));
                   prnSet.add(MediaSizeName.ISO_A4);
                   PageFormat pf = prnJob.defaultPage();
                   pf.setOrientation(java.awt.print.PageFormat.PORTRAIT);
                   prnJob.setJobName(jobName);
                   PrintService[] services = PrinterJob.lookupPrintServices();
                   if (services.length > 0)
                        if (prnJob.printDialog(prnSet))
                              * Get print date
                             String dateFormat = "dd/MM/yyyy HH:mm:ss";
                             DateFormat m_DateFormat = new SimpleDateFormat(dateFormat);
                             lastPrintDate = m_DateFormat.format(new Date()).toString();
                             prepareForPrint();
                             prnJob.print(prnSet);
                   else
                        JOptionPane.showMessageDialog(m_parent, "No Printer was found!!", "Printer Error", JOptionPane.ERROR_MESSAGE);
                        return;
              catch (PrinterException e)
                   e.printStackTrace();
         public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException
               * Check if this is the first time the print method is called for this print action.
               * It is not guaranteed that the print will be called with synchronous pageIndex'es,
               * so we need to calculate the number of pages and which rows appear on which pages.
               * Then the correct page will be printed regardless of which pageIndex is sent through.
              if (first_pass)
                   calcPages(g, pageFormat);
              first_pass = false;
              // Stop printing if the pageIndex is out of range
              if (pageIndex >= pages.size())
                   return NO_SUCH_PAGE;
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() + pageFormat.getImageableY();
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = (pageWidth - (cellBuffer * tableView.getColumnCount())) / tableWidth;
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              double test = 0;
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)Math.floor(tableView.getColumnModel().getColumn(i).getWidth() * scale);
                   test += columnWidths;
              // Reset the view to the start of the page
              g2.translate(0, 0);
              // Draw a rectangle to see the printable area
              g2.draw3DRect((int)pageFormat.getImageableX(),
                        (int)pageFormat.getImageableY(),
                        (int)pageFormat.getImageableWidth(),
                        (int)pageFormat.getImageableHeight(),
                        false);
              // Calculate the header height
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              // Print the headers and retreive the starting position for the data
              int next_row = (int)pageFormat.getImageableY() + fontMetrics.getHeight();
              if ((m_title != null) && (!m_title.equalsIgnoreCase("")))
                   g2.drawString(m_title,
                                       (int)(pageFormat.getImageableX()),
                                       next_row);
                   Color current_color = g2.getColor();
                   g2.setColor(Color.lightGray);
                   int y = next_row + fontMetrics.getDescent();
                   g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                                  y,
                                  (pageFormat.getImageableY() + pageFormat.getImageableWidth()),
                                  y));
                   g2.setColor(current_color);
                   next_row += fontMetrics.getHeight();
              next_row = printLine(g2, pageFormat, fontMetrics, -1, next_row, columnWidths);
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              // Start printing the detail
              ArrayList page = (ArrayList)pages.get(pageIndex);
              int start = ((Integer)page.get(0)).intValue();
              int end = ((Integer)page.get(1)).intValue();
              for (int i = start; i <= end; i++)
                   next_row = printLine(g2, pageFormat, fontMetrics, i, next_row, columnWidths);
              // Print the footer
              g2.setFont(footerFont);
              String pageFooter = "Page " + (pageIndex + 1) + " - " + lastPrintDate;
              g2.drawString(pageFooter,
                             (int)pageFormat.getWidth() / 2 - (fontMetrics.stringWidth(pageFooter) / 2),
                             (int)(pageHeight - fontDescent));
              return PAGE_EXISTS;
         * We can't guarantee that the same amount of rows will be displayed on each page,
         * the row heights are dynamic and may wrap onto 2 or more lines.
         * Thus we need to calculate the height of each row and then test how may rows
         * fit on a specific page. eg. Page 1 contains rows 1 to 10, Page 2 contains rows 11 to 15 etc.
         public void calcPages(Graphics g, PageFormat pageFormat) throws PrinterException
              Graphics2D     g2 = (Graphics2D) g;
              g2.setColor(Color.black);
              // The footer will be one line at the bottom of the page, cater for this.
              g2.setFont(footerFont);
              footerHeight = g2.getFontMetrics().getHeight() + g2.getFontMetrics().getDescent();
              g2.setFont(defaultFont);
              FontMetrics fontMetrics = g2.getFontMetrics();
              int fontHeight = fontMetrics.getHeight();
              int fontDescent = fontMetrics.getDescent();
              double pageHeight = pageFormat.getImageableHeight() - fontHeight;
              double pageWidth = pageFormat.getImageableWidth();
              double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
              // Shrink or expand the table to fit the page width
              double scale = (pageWidth - (cellBuffer * tableView.getColumnCount())) / tableWidth;
              // Calculate the width in pixels for each column
              double[] columnWidths = new double[tableView.getColumnCount()];
              for(int i = 0; i < tableView.getColumnCount(); i++)
                   columnWidths[i] = (double)Math.floor(tableView.getColumnModel().getColumn(i).getWidth() * scale);
              // Calculate the header height
              int maxHeight = 0;
              g2.setFont(headerFont);
              fontMetrics = g2.getFontMetrics();
              headerHeight = 0;
              if ((m_title != null) && (!m_title.equalsIgnoreCase("")))
                   headerHeight = fontMetrics.getHeight();
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = tableView.getColumnName(j).toString();
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
              headerHeight += g2.getFontMetrics().getHeight() * maxHeight;
              g2.setFont(defaultFont);
              fontMetrics = g2.getFontMetrics();
              int pageNum = 0;
              int bottom_of_page = (int)(pageFormat.getImageableHeight() + pageFormat.getImageableY()) - footerHeight;
              int prev_row = 0;
              int next_row = (int)pageFormat.getImageableY() + fontHeight + headerHeight;
              int i = 0;
              ArrayList page = new ArrayList();
              page.add(new Integer(0));
              for (i = 0; i < tableView.getRowCount(); i++)
                   maxHeight = 0;
                   for (int j = 0; j < tableView.getColumnCount(); j++)
                        String value = formatObject(tableView.getValueAt(i, j));
                        int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                        if (numLines > maxHeight)
                             maxHeight = numLines;
                   prev_row = next_row;
                   next_row += (fontHeight * maxHeight);
                   // If we've reached the bottom of the page then set the current page's end row
                   if (next_row > bottom_of_page)
                        page.add(new Integer(i - 1));
                        pages.add(page);
                        page = new ArrayList();
                        page.add(new Integer(i));
                        pageNum++;
                        next_row = (int)pageFormat.getImageableY()
                                       + fontHeight
                                       + ((int)pageFormat.getHeight() * pageNum)
                                       + headerHeight;
                        bottom_of_page = (int)(pageFormat.getImageableHeight()
                                            + pageFormat.getImageableY())
                                            + ((int)pageFormat.getHeight() * pageNum)
                                            - footerHeight;
                        //Include the current row on the next page, because there is no space on this page
                        i--;
              page.add(new Integer(i - 1));
              pages.add(page);
         * Print the headers or a row from the table to the graphics context
         * Return the position of the row following this one
         public int printLine(Graphics2D g2,
                                       PageFormat pageFormat,
                                       FontMetrics fontMetrics,
                                       int rowNum,
                                       int next_row,
                                       double[] columnWidths)
                   throws PrinterException
              int lead = 0;
              int maxHeight = 0;
              for (int j = 0; j < tableView.getColumnCount(); j++)
                   String value = null;
                   int align = LEFT_ALIGN;
                   if (rowNum > -1)
                        Object obj = tableView.getValueAt(rowNum, j);
                        if (obj instanceof Number)
                             align = RIGHT_ALIGN;
                        value = formatObject(obj);
                   else
                        //align = CENTER_ALIGN;
                        value = tableView.getColumnName(j);
                   int numLines = (int)Math.ceil(fontMetrics.stringWidth(value) / columnWidths[j]);
                   if (numLines > maxHeight)
                        maxHeight = numLines;
                   if (fontMetrics.stringWidth(value) < columnWidths[j])
                        // Single line
                        int offset = 0;
                        // Work out the offset from the start of the column to display alignment correctly
                        switch (align)
                             case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)); break;
                             case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value)) / 2; break;
                             default: offset = 0; break;
                        g2.drawString(value,
                                       lead + (int)(pageFormat.getImageableX() + offset),
                                       next_row);
                   else
                        for(int a = 0; a < numLines; a++)
                             //Multi-Line
                             int x = 0;
                             int width = 0;
                             for(x = 0; x < value.length(); x++)
                                  width += fontMetrics.charWidth(value.charAt(x));
                                  if (width > columnWidths[j])
                                       break;
                             int offset = 0;
                             // Work out the offset from the start of the column to display alignment correctly
                             switch (align)
                                  case RIGHT_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value.substring(0, x))); break;
                                  case CENTER_ALIGN: offset = (int)(columnWidths[j] - fontMetrics.stringWidth(value.substring(0, x))) / 2; break;
                                  default: offset = 0; break;
                             g2.drawString(value.substring(0, x),
                                            lead + (int)(pageFormat.getImageableX() + offset),
                                            next_row + (fontMetrics.getHeight() * a));                    
                             value = value.substring(x);
                   lead += columnWidths[j] + cellBuffer;
              // Draw a solid line below the row
              Color current_color = g2.getColor();
              g2.setColor(Color.lightGray);
              int y = next_row + (fontMetrics.getHeight() * (maxHeight - 1)) + fontMetrics.getDescent();
              g2.draw(new Line2D.Double(pageFormat.getImageableX(),
                             y,
                             (pageFormat.getImageableY() + pageFormat.getImageableWidth()),
                             y));
              g2.setColor(current_color);
              // Return the position of the row following this one
              return next_row + (fontMetrics.getHeight() * maxHeight);
         public String formatObject(Object obj)
              String value = (obj == null) ? "" : obj.toString();
              return value;

Maybe you are looking for

  • System and sysdba difference?

    Hello ; What is the difference between system and "as sysdba" difference? IS there anything beyond to be a superuser in ORacle world? I installed an Oracle and worked on it for a few days in order to set up a connection from sqlplus. Now I can connec

  • My Auto-Brightness is not working on my iPhone5

    My IPhone5 auto-brightness is not working I don't know if it is a bug or what please help. Thank You

  • PS CC Clone Stamp moving whole image?

    I have a problem that I hope someone may be able to help me with. When I use the clone stamp I 'Alt-Click' to select a point to clone from. When I try to actually do the cloning the whole image moves on top of the original image. I knew it would be h

  • Help!  Bought an IPod from a PC user, now I can't connect it to my Mac!

    I bnought an IPod from a friend who was using it with a PC. I erased all of it's memory and then restored it using the IPod updater software I got from apple.com. Now, I can't connect it to my Mac, and the IPod screen goes from the "apple" display, t

  • Distribute by key part 2

    Hello Gurus, I am not having a system with me now. Year- Version-Product-Factory-Quantity 2007- V1P1--W1-- 10 2007- V1P1--W2-- 20 2007- V1P1--W3-- 70 1. How should i configure the key such that the number of records is unknown or variable? 2. If  Top