Jdk1.4 printing and AttibuteSets.

Hi!
I'm trying to create a HTML -> PS filter, and I'm stumbling on the goal line... I bring up the URL in a HTML component, then use the new 1.4 printing API to write out PS. Unfortunately, my attributes seem to be ignored. I need to set attributes programatically (instead of via a PrintRequest) since my program is headless.
Time for some code. Here's the actuall attibute handling and printing:
     PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
     // Gray scale only, this is for faxes after all
     aset.add(Chromaticity.MONOCHROME);
     // Try to set right paper and reasonable margins.
     // A4=210x297 mm. 1 cm margins
     aset.add(MediaSizeName.ISO_A4);
     aset.add(new MediaPrintableArea(10, 10, 190, 277, MediaPrintableArea.MM));
     Printable p=new ComponentPrintable(c);
     Doc doc = new SimpleDoc(p, flavor, null);
     pj.print(doc, aset);I'm skipping some of the preliminaries, but everything works except the attributes so I focused on that bit.
Here's my ComponentPrintable:
static class ComponentPrintable implements Printable {
    Component component;
     ComponentPrintable(Component c) {
          component=c;
     public int print(Graphics g,PageFormat pf,int pageIndex) {
          if (pageIndex == 0) {
               Graphics2D g2d= (Graphics2D)g;
               double x0=pf.getImageableX(), y0=pf.getImageableY();
               double pw=pf.getImageableWidth(), ph=pf.getImageableHeight();
               int cw=component.getWidth(), ch=component.getHeight();
               double sc=((double)pw)/cw;
               System.out.println("Page dimension: ("+x0+","+y0+")-("+(x0+pw)+","+(y0+ph)+")");
               System.out.println("Comp dimension: "+cw+"x"+ch);
               System.out.println("Translate "+x0+","+y0);
               System.out.println("Scale "+sc);
               g2d.translate(x0, y0);
               g2d.scale(sc, sc);
               component.paint(g2d);
               return Printable.PAGE_EXISTS;
          } else {
               return Printable.NO_SUCH_PAGE;
}Output from the ComponentPrintable when run:
Page dimension: (72.0,72.0)-(540.0,720.0)
Comp dimension: 681x1009
Translate 72.0,72.0
Scale 0.6872246696035242
Page dimension: (72.0,72.0)-(540.0,720.0)
Comp dimension: 681x1009
Translate 72.0,72.0
Scale 0.6872246696035242One inch margin. And when viewing the PS file it turns out it's in color as well.
Why oh why aren't my attributes respected? Any and all suggestions welcomed.

Well, I was trying to use the unified printing APIs in 1.4, ie. javax.print.DocPrintJob and so forth. If you do it that way there is no PageFormat, just the attributes. In 1.3 style printing there was no way to print to a PostScript file.
But, lo and behold, I checked out the docs for 1.3-style printing (java.awt.print) in 1.4 and they have added methods to select a StreamPrintService based on output flavor. Then I could use a plain old PrintJob and PageFormat to fix the margins.
I'll give you partial credit for leading my right. However, I also need to get grayscale to work. The client's PS printing program crashes on 'textcolor' commands. :-(
Finished code if anyone is interested:
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
PrinterJob pj = PrinterJob.getPrinterJob();
StreamPrintServiceFactory[] factories =
     PrinterJob.lookupStreamPrintServices(psMimeType);
if (factories.length == 0) {
     System.err.println("No suitable factories");
     return false;
try {
     FileOutputStream fos = new FileOutputStream(f);
     StreamPrintService sps = factories[0].getPrintService(fos);
     pj.setPrintService(sps);
     PageFormat pf=pj.defaultPage();
     Paper p=new Paper();
     p.setSize(210*72d/25, 297*72d/25);
     p.setImageableArea(10*72d/25,10*72d/25, 190*72d/25,277*72d/25);
     pf.setPaper(p);
     pj.setPrintable(new ComponentPrintable(c), pf);
     pj.print();
} catch (Exception x) {
     x.printStackTrace();
     return false;
return true;

Similar Messages

  • Unsupport feature SQL exception ---JDK1.4 and oracle 10g driver

    here there,
    I got the unsupport feature SQLexeption, does anybody have any idea? JDK1.4 and oracle 10g driver should fully support JDBC 3.0. Am I right ?
    Thank you very much
    Avni
    here is my snippet code,
    Connection con = DriverManager.getConnection(url, user, password);
              DatabaseMetaData data = con.getMetaData();
              int jdbcVersion = data.getJDBCMajorVersion();
    and here is the exception,
    java.sql.SQLException: Unsupported feature
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
         at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
         at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:690)
         at oracle.jdbc.OracleDatabaseMetaData.getJDBCMajorVersion(OracleDatabaseMetaData.java:4061)
         at com.sbc.jdbc.ConnectionVersion.<init>(ConnectionVersion.java:36)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80)
         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:44)
         at java.lang.reflect.Constructor.newInstance(Constructor.java:315)
         at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:93)

    Avni,
    Works for me with Oracle 10g database, "ojdbc14.jar" JDBC driver (latest version -- 10.2.0.1.0 -- downloaded from OTN) and JDK 1.4.2_07:
    conn = ods.getConnection();  // Using 'OracleDataSource'
    DatabaseMetaData dbmd = conn.getMetaData();
    System.out.println("JDBC Major Version: " + dbmd.getJDBCMajorVersion());Above code prints out:
    JDBC Major Version: 10Good Luck,
    Avi.

  • I am having trouble printing to an Epson XP600.  It is a new printer and it has been replaced because we thought it was the printer.  Basically, when I print from Excel, only color will print.

    I am having trouble printing to an Epson XP600.  We have replaced the printer and we are still having the same problem.  When I try to print from Excel, only the color prints.  Any suggestions?

    Has anyone else had issues not being able to print black (such as a document)?  My photos print great, but when I try to print a simple black-ink document, it won't work. Any suggestions?

  • I have an wireless printer and a new wifi router. I have set the printer and iPhone / iPad correctly to the new router but when i try to print it won't recognise the air printer. Help. All was working fine on my old router

    I Have a new wifi router and have set up my iPad / iPhone and wireless printer correctly  to the new router but I can't print from the iPad and iPhone. It keeps saying ' no AirPrint printer found'. Help please!

    Start with the most basic thing that you can try. Unplug the router from power for about 30 seconds, and restart the printer and the iPad and plug the router back into power.

  • We just added a new printer and bluetooth connection to our iMac.  Now iTunes does not recognize our iPads as devices.  Have already tried restarting everything.  Any other suggestions?

    We just added a new printer and bluetooth connection to our iMac.  Now iTunes does not recognize our iPads as devices.  Have already tried restarting everything.  Any other suggestions?

    You can try the steps recommended here: http://www.apple.com/support/ipad/assistant/itunes/

  • Just bought a new printer and download the software

    Hi,
    I just bought a new printer and I need to be able to print all of my homework assignments off but i tried to come to the website on several occassions, the site is always down. So what do I need to do next? Do I call someone about the problem or do I just take the printer back and buy another one from another company. And I do not have a CD drive for my small laptop.

    Hi,
    What is your printer and the Operating system of your small laptop ?
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • I installed a new printer and now Photoshop Elements tells me I can't print.  The error message is "The saved printer information is not compatible with this version of Photoshop Elements, or the saved printer is no longer available.  You will need to che

    I installed a new printer and now Photoshop Elements tells me I can't print.  The error message is "The saved printer information is not compatible with this version of Photoshop Elements, or the saved printer is no longer available.  You will need to check your printer settings before printing."  I have uninstalled and re-installed Photoshop Elements, checked my printer settings and still I can't print a photo.

    Hi ,
    Please update to PSE 13.1
    13.1 has solved this problem.
    Refer to this link.
    Photoshop Elements Help | Printer errors with Photoshop Elements 13

  • Installed a new printer and one line on the top is skipped

    Appreciate your inputs.
    We have been using the 'Check Printing report' for quite a while; We recently installed a new printer and we see that the alignment has gone wrong.
    The checks are printing from one line below as it is skipping one line. Where do we adjust the setting so that the printing starts from the place where we want?
    Thanks in advance

    Hi
    Im no expert but I doubt its a template issue more likely to be the control escape sequence on the printer diriver set up. Check your printer manual and the current set up you have.
    Regards
    Tim

  • I have a new printer and can't get it to print. ink installed properly. any ideas?

    Please help me. I have a new printer set up today and it doesn't print. It is wireless and drivers installed correctly as is the inks x 2. It says printing alignment page but nothing comes out. Any suggestions for me? Thanks kindly,
    Sue

    Try to perform a HARD RESET on the printer first. Unplug the power cord from the printer, and leave it out for 30 seconds. Plug it back in, see if it aligns and finishes the job.
    After alignment, try to print a test page from the printer or make a copy. This job is to make sure that the HARDWARE of the printer is working correctly.
    **Click the KUDOS star on the left to say 'Thanks'**
    Please mark a reply "ACCEPTED AS SOLUTION" if it solved your problem, so others can find it.

  • Set The Secured Files, Not allow printing and saving to another location

    Dear Sir / Madam,
    Please help...
    Possible to set the security permission for share files, not allow end users to printing and saving a PDF to another location.
    Thanks,
    Alex Tai

    Hi Alex,
    Possible to set the security permission for share files, not allow end users to printing and saving a PDF to another location.
    Based on my tests, users can save the document with only Read permission, which is by design. If you don’t want users to print files, please do not give the print permissions on printers.
    Best Regards,
    Amy
    Please remember to mark the replies as answers if they help and un-mark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • How do I use the filter to automatically print email and .pdf, .xls, .doc attachments to my default network printer and to other network printers

    I receive sales orders by email. I want to filter some to print on my default network printer and others to print on another network printer. The email body must print as well as txt, .pdf, .xls, .doc attachments.

    You can filter messages to file them to a certain folder, but I don't think you can have Thunderbird to automatically print them.

  • HP Solution Center stopped working and HP Print and Scan Doctor cannot find my OJ4680

    HP Solution Center came installed on my HP G60 notebook with Windows 7 premium 64 bit.  It suddenly stopped working--it says it cannot run because the device installation is not complete.  If I open HP Sup0ort Assistant it says the OJ4680 is ready and it is designated as the default printer in Printers and Devices but when I try to run HP Print and Scan Doctor it cannot find it--it can only find OJ4500 which I use when I'm in my second home.  Please help me fix this as at this point I can't print or scan. 

    Thanks for the help and quick response.  I haven't tried your solution yet because before I received your instructions I updated the drivers again and it appears to be working though I've had a message since then that I couldn't scan because my device was offline which was not true as I had just printed a document.  I used HP Print and Scan doctor and followed the steps which included turning the device off and unplugging it for 60 seconds.  I can now copy, print and scan but I still have the yellow triangles with exclamation points on both my PC and all in one.  I'm not sure I want to do more at this point since everything is working well at the moment. BTW my laptop is set for automatic updates by HP and Microsoft, why didn't they keep this problem from occurring?

  • Network Connection Failures Affecting Printing and Finder Access

    I have a Canon MX320 connected via USB to my iMac running OSX 10.9.1.  The latest Canon printer drivers are installed.  Everything works fine with this printer and computer combination.  The printer is enabled for shaing over the network.
    The problem is that occasionally, the iMac seems to disconnect from any other laptop or desktop computer (Macs or PCs) connected through my wireless router.  On a mac laptop (also with OSX 10.9.1) I may lose access to shared directories on the iMac, and more often, I lose the ability to print from the laptop.  The print queues are unchanged on all Macs, but remote printing over the network fails with the message "printer not connected", even though the only change may have been that the iMac hosting the printer went to sleep. 
    Sometimes, waking the iMac allows the network print job to go through, but typically not if the print job is initiated before waking the iMac.  The printer queue on the laptop will seem fine, with "printer idle", but as soon as the print job is submitted, it briefly reports "looking for printer", and then "printer not connected".  Sometimes, everything (iMac and laptop) needs to be rebooted to re-establish a network printing connection through the iMac. 
    Trying to reset or delete and re-install the printer queue on the laptop does not fix the problem.  I am assuming that this is because the remote connection to the server (the iMac) has effectively been interrupted or lost.  The iMac may show up in a Finder window on the laptop as a simple PC icon, but with none of the connected directories visible.  trying to re-mount the remote directories by connecting to the "server" (the iMac) often fails.  It is as if something has happened to break the connection to the iMac, and both Finder and network printing are thereby disabled until everything is rebooted.
    Printer error log entries:
    E [13/Feb/2014:08:21:43 -0500] Unknown directive BrowseOrder on line 9 of /private/etc/cups/cupsd.conf.
    E [13/Feb/2014:08:21:44 -0500] Unknown directive BrowseAllow on line 10 of /private/etc/cups/cupsd.conf.
    This problem is intermittent but seems to be happening often after the Mavericks upgrade.  One should not have to wake up a remote computer prior to connecting to it, or asking a printer connected to it to print a job.

    Hello Rescue_2003
    Check to see if Wake for network access is checked in System Preferences > Energy Saver.
    OS X Mavericks: Share your computer’s resources when it’s in sleep
    http://support.apple.com/kb/PH14244
    Regards,
    -Norm G.

  • Suddenly My iphone 4s does not find my wireless printer and sometimes can't find the server.

    All of a sudden My iPhone 4s cannot find my wireless printer and cannot connect to the internet all of t he time.

    Hi dbutkow,
    If you are having Wi-Fi or network connectivity issues, you may want to take a look at the troubleshooting steps outlined in this article:
    iOS: Troubleshooting Wi-Fi networks and connections
    http://support.apple.com/kb/ts1398
    Cheers,
    - Brenden

  • A "HP Twain Scan" function in the "Print and Scan Doctor" app - Solution?

    Frustration!! Why can't I get the scanning portion of subject printer to work on my laptop Windows 7 (64-bit)!?? I've tried the Print and Scan Doctor several times, and the same dysfunction says "HP Twain Scan" whatever that means or is? I've pulled out the cords, all of 'em, and it still not helping.  Did I purchase a printer that is not compatible with my laptop? As far as the scanning portion is concerned, or what?  I can print OK, both from website/emails and my own documents.  I do a lot of scanning (photos mostly), and so this will be a sad problem.Hoping someone out there in techland can give me a solution. Thanks!

    Hi , Welcome to the HP Forums! I understand that you cannot scan with your HP Envy 7645 on Windows 7. I am happy to look into this scanning issue for you! Some questions for you: Are you able to make copies with the printer? Copying Documents or Photos with an HP ENVY 5640, 5660, 7640 e-All-in-One, HP Officejet 5740 and 8040 e-All-in-One Printer Series.How is the printer connected? Wireless, Ethernet, or USB? In the meantime, please try the steps within this scanning guide, A 'No Computer Found', 'Connection Required', or 'Scan Unsuccessful' Message Displays for HP ENVY 5640, 5660, 7640 and Officejet 5740, 8040 e-All-in-One Printer Series, and let me know what happens! Hope to hear from you soon!  “Please click the Thumbs up icon below to thank me for responding.”

Maybe you are looking for