Printing HTML Docs with JPS ???

Hello!
How can I print a HTML-File with Java Printing Service (not the source, but the view of it) ???
Some experience???
kind regards
pedros25

I'm currently trying to do just that. My problem is
that in order to get a lengthy HTML document to
print, you have to have an object that
implements the Pageable interface. The two methods
I'm having trouble with are
getNumberOfPages()
This returns the number of pages in the Print job.
How do I calculate the number of pages in an HTML
document?
getPrintable(int pageIndex)
For this part, I just rerturn a reference to the JScrollPane which contains the JEditorPane. However,
I also have to get it to scroll to the appropriate
page. Right now I'm using the following:
public void goPage(int pageIndex)
int block = pane.getScrollableBlockIncrement(scroller.getViewport().getViewRect() ,SwingConstants.VERTICAL,1);
int newVal = block*pageIndex;
//scroller.getVerticalScrollBar().setValue(newVal);
scroller.getViewport().scrollRectToVisible(new Rectangle(0,newVal,this.getSize().width,block));
But this seems to be causing a few lines to be skipped
between each page. Any ideas on how to implement the
pageable interface for a JScrollPane that contains a
JEditorPane which contains an HTMLDocument?

Similar Messages

  • Printing pdf/postscript with JPS 1.4 -- HELP!

    Hi all,
    I've been experimenting with the new java printing service and I have run into a couple problems. In particular, I have been trying to get even the most basic example referring to printing a postscript file directly to a printer. The code is pretty much straight from sun's JPS section.
    here's the code:
    // Input the file
    FileInputStream textstream = null;
    try {
    textstream = new FileInputStream("c:/0011.ps");
    } catch (FileNotFoundException ffne) {
    if (textstream == null) {
    return;
    // Set the document type
    DocFlavor myFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;
    // Create a Doc
    Doc myDoc = new SimpleDoc(textstream, myFormat, null);
    // Build a set of attributes
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    //aset.add(MediaSize.A4);
    aset.add(Sides.DUPLEX);
    // discover the printers that can print the format according to the
    // instructions in the attribute set
    PrintService[] services =
    PrintServiceLookup.lookupPrintServices(myFormat, aset);
    // Create a print job from one of the print services
    if (services.length > 0) {
    DocPrintJob job = services[0].createPrintJob();
    try {
    job.print(myDoc, aset);
    } catch (PrintException pe) {
    System.out.println("error");
    Now....I've just installed printer drivers in Windows 2K for a RICOH and CANON iR550 printer. Both printers support PS3 and the RICOH Aficio AP2700 PS printer also supports IPP (Note: I physically don't have these printers, so I'm just printing to a file and viewing the file with a PCL viewer).
    okay...now...the problem at hand....I can do the following with the code above:
    1) I can print a postscript file to the printer with NO attributes specified...once I add Copies and Media types..no services are found...
    2) specifying a PDF docflavor and pdf file will not return any services.
    3) If I specify AUTOSENSE in the docflavor, the PDF will be sent to the printer but 'junk' will be printed out. Basically, the printer doesn't seem to understand the file type.
    I've tried other printer drivers from other printer companies with no success.
    Now, my question to everyone who has SUCCESSFULLY printed PDF/Postscript with the Java Print Service using attributes such as Mediasize, Duplex printing, Copies...please...please respond to this message and provide some insight on how you did it (i.e. printer type, drivers, code snippit, etc...)
    am I missing something?
    I know alot of people having the same problem...
    Thankyou

    Hi,
    You may want to check the DocFlavors that are supported by the printers.
    Using the command as followed,
    // Get the supported flavour
    DocFlavor[] docFlavors = printer.getSupportedDocFlavors();
    for (int i=0; i < docFlavors.length; i++) {
    System.out.println("Supported flavour is " + docFlavors);
    I also hit into the same problem like you, trying to print a PDF into HP LaserJet 5 using AUTOSENSE. Junk output.
    Check the docFlavor supported on the printers are
    Supported flavour is image/gif; class="[B"
    Supported flavour is image/gif; class="java.io.InputStream"
    Supported flavour is image/gif; class="java.net.URL"
    Supported flavour is image/jpeg; class="[B"
    Supported flavour is image/jpeg; class="java.io.InputStream"
    Supported flavour is image/jpeg; class="java.net.URL"
    Supported flavour is image/png; class="[B"
    Supported flavour is image/png; class="java.io.InputStream"
    Supported flavour is image/png; class="java.net.URL"
    Supported flavour is application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    Supported flavour is application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    Supported flavour is application/octet-stream; class="[B"
    Supported flavour is application/octet-stream; class="java.net.URL"
    Supported flavour is application/octet-stream; class="java.io.InputStream"
    However, do not know how to create a print service to support PDF. Obviously, we know that HP LaserJet 5 can print PDF.
    Regards
    Heng

  • Problem Printing html page with JEditorPane...

    Hello All,
    I Have a problem in printin html file with JEditorPane...
    My Html file contains a Table on it..
    Problem is that JEditorPane displays the html file correctly but
    it prints the file without print that Table..
    So pls help me...
    Thanx in advance,..
    Amit
    [email protected]

    I think you would know how to retrieve content of an HTML page using the URL object. Just in case.
    My apology if this short note doesn't help you at all.

  • Print html file with barcode from abap report

    hi
    i am printing html file from abap program using gui_execute.
    i am using netscape.exe , its printing first time and when reprint its not working
    basically html file contains gif file which has fedex barcode.
    could you please let me know how to print html file from report

    DGU wrote:
    where to check RAW or TEXT? the print report vi only asks for file name and printer name.
    When I print from notepad, everything just goes by default. This is a label printer, so I never need to specify printing parameter such as size, orientation, etc in the past
    Famous last words go something like this: "...never had to do that before."  Maybe you have to do that now.  It's worth at least comparing the defaults settings for bothe generic drivers.  It could save you a lot of headache if you notice something different.
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

  • How can I view all comments in a Pages doc and print the doc with comments?

    It seems that we can no longer view comments in the margin of a document.  It is also not possible to print the document with comments visible.  Anyone else having this problem?  Pages 09 Help does not even offer an up-to-date explanation.  "Show Comments" only shows color shading.  The option “Show Comments and Changes Pane" does not even exist.  How can I get the comments to print???

    You will have to wait for Apple to fix this deficiency in a forthcoming update to Pages v5. Or, you could use Pages ’09 v4.3, if originally installed before the v5 upgrade, and located in /Applications/iWork '09.
    Otherwise, use another solution (e.g. Office for Mac 2011, LibreOffice).

  • "invalid flavor error" Printing html docs

    DocFlavor flavor = DocFlavor.URL.TEXT_HTML_US_ASCII;
    I need to print a URL with an applet in Internet Explorer but keep getting the "invalid flavor" error.
    please post your answer in the following topic:
    http://forum.java.sun.com/thread.jsp?thread=350123&forum=57&message=2630553
    Thanks

    i tried to print all the flavors that my printer supports but i didn't understand the output.
    This is part of my code:
          DocFlavor[] flavors = service.getSupportedDocFlavors();
          for (int i = 0; i < flavors.length; i++) {
             cade1 += "\n" + flavors.toString();
          System.out.println(cade1);
          System.out.println("\n" + service.getName());This is the output of the app:
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    [Ljavax.print.DocFlavor;@f62373
    \\data1\canonAny help?
    This is frustrating me quite a bit... I've been trying to print for months so far.
    Thanks,
    Silvio Sisto

  • Print html report with waveform

    I'm trying to make a report on my system using print from the File menu, and then saving the report as a html document. However, I don't seem to get the descriptions for waveforms in the report.
    I've tried on both WIN-NT and WIN-2000 machines, but still no description.
    Would also want to know if it is possible not to include descriptions of parts of clusters (such as waveforms or error clusters), but instead just include the description of the cluster itself.

    > Unfortunately, what you see in the Print window is all the options
    > available. You can print description for only the icon, for all
    > controls, or for connected controls. You cannot select to print
    > description of only few controls. However, I tested this and was able
    > to print description for a waveform chart.
    > You can suggest this additional feature if you go to ni.com, click on
    > "Contact NI" in the top right corner, and then select "feedback" under
    > Product Feedback.
    In the meantime, you can use the report generation VIs to make a custom
    report. Use a property node to read the description and add it wherever
    you like.
    Greg McKaskle

  • 2620 prints word docs with missing text

    I just purchased an offcejet 2620 and it will not print out my word documents correctly. There are missing lines of text and cannot figure out why. I am using a MacBook Air OSX 10.9.4 I need help please! 
    Thanks

    Hi donandsteph,
    Welcome to the HP Forums!
    I see that your HP Officejet 2620 will not print your Word Documents correctly on Mac OS X 10.9.4. I am happy to help!
    I would recommend this print quality guide. Fixing Ink Streaks, Faded Prints, and Other Common Print Quality Problems.
    Hope this guide helps, and let me know if you have any further issues!
    RnRMusicMan
    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 the “Kudos Thumbs Up" to say “Thanks” for helping!

  • Printing HTML with Java Printing Service(JDK1.4 beta)

    Hi there!
    I'm currently checking out the new Java Printing Service (JPS) in the new JDK1.4 beta. This looks like a very promising printing API, with amongst others printer discovery and support for MIME types - but I have some problems with printing HTML displayed in a JEditorPane.
    I'm developing an application that should let the user edit a (HTML)document displayed in a JEditorPane and the print this document to a printer. I have understood that this should be peace-of-cake using the JPS which has pre-defined HTML DocFlavor amongst others, in fact here is what Eric Armstrong says on Javaworld (http://www.javaworld.com/javaone01/j1-01-coolapis.html):
    "With JPS, data formats are specified using MIME types, for example: image/jpeg, text/plain, and text/html. Even better, the API includes a formatting engine that understands HTML, and an engine that, given a document that implements the Printable or Pageable interface, generates PostScript. The HTML formatting engine looks particularly valuable given the prevalence of XML data storage. You only need to set up an XSLT (eXtensible Stylesheet Language Transformation) stylesheet, use it to convert the XML data to HTML, and send the result to the printer."
    After one week of reasearch I have not been able to do what Armstrong describes; print a String that contains text of MIME type text/html.
    I have checked the supported MIMI types of the Print Service returned by PrintServiceLookup.lookupDefaultPrintService(). This is the result:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new Copies(2));
    PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,aset);
    if (service.length > 0) {
    System.out.println("Selected printer " + service[0].getName());
    DocFlavor[] flavors = service[0].getSupportedDocFlavors();
    for (int i = 0;i<flavors.length;i++) {
    System.out.println("Flavor "+i+": "+flavors.toString());
    Selected printer \\MUNIN-SERVER\HP LaserJet 2100 Series PCL 6
    Flavor 0: image/gif; class="[B"
    Flavor 1: image/gif; class="java.io.InputStream"
    Flavor 2: image/gif; class="java.net.URL"
    Flavor 3: image/jpeg; class="[B"
    Flavor 4: image/jpeg; class="java.io.InputStream"
    Flavor 5: image/jpeg; class="java.net.URL"
    Flavor 6: image/png; class="[B"
    Flavor 7: image/png; class="java.io.InputStream"
    Flavor 8: image/png; class="java.net.URL"
    Flavor 9: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    Flavor 10: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    As you can see there is no support for text/html here.
    If anyone has a clue to what I'm missing here or any other (elegant, simple) way to print the contents of a JEditorPane, please speak up!
    Reply to: [email protected] or [email protected] or here in this forum

    Since you have 'printable' as one of your flavors, try this using a JTextPane (assuming you can dump your HTML into a JTextPane, which shouldn't be a big problem)...
    1. Have your JTextPane implement Printable
    ie. something like this:
    public class FormattedDocument extends JTextPane implements Printable 2. Read your HTML into the associated doc in the text pane.
    3. Implement the printable interface, since you have it as one of your available flavors (I'd imagine everybody has printable in their available flavors). Something like this:
    public int print(Graphics g, PageFormat pf, int pageIndex) {
            Graphics2D g2 = (Graphics2D) g;
            g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
            g2.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight()); 
            if (pageIndex == 0)
                setupPrintView(pf);
            if (!pv.paintPage(g2, pageIndex))
                return NO_SUCH_PAGE;
            return PAGE_EXISTS;
        }Here's my setupPrintView function, which is executed once on page 0 (which still needs some polishing in case I want to start from page 5). It sets up a 'print view' class based on the root view of the document. PrintView class follows...
    public void setupPrintView(PageFormat pf) {
    View root = this.getUI().getRootView(this);
            pv = new PrintView(this.getStyledDocument().getDefaultRootElement(), root,
                               (int)pf.getImageableWidth(), (int)pf.getImageableHeight());Note of obvious: 'pv' is of type PrintView.
    Here's my PrintView class that paints your text pane line by line, a page at a time, until there is no more.
    class PrintView extends BoxView
        public PrintView(Element elem, View root, int w, int h) {
            super(elem, Y_AXIS);
            setParent(root);
            setSize(w, h);
            layout(w, h);
        public boolean paintPage(Graphics2D g2, int pageIndex) {
            int viewIndex = getTopOfViewIndex(pageIndex);
            if (viewIndex == -1) return false;
            int maxY = getHeight();
            Rectangle rc = new Rectangle();
            int fillCounter = 0;
            int Ytotal = 0;
            for (int k = viewIndex; k < getViewCount(); k++) {
                rc.x = 0;
                rc.y = Ytotal;
                rc.width = getSpan(X_AXIS, k);
                rc.height = getSpan(Y_AXIS, k);
                if (Ytotal + getSpan(Y_AXIS, k) > maxY) break;
                paintChild(g2, rc, k);
                Ytotal += getSpan(Y_AXIS, k);
            return true;
    // find top of page for a given page number
        private int getTopOfViewIndex(int pageNumber) {
            int pageHeight = getHeight() * pageNumber;
            for (int k = 0; k < getViewCount(); k++)
                if (getOffset(Y_AXIS, k) >= pageHeight) return k;
            return -1;
    }That's my 2 cents. Any questions?

  • Problem with NIReport.llb\Print HTML Report using IE.vi on different machines

    We have 5 machines here in our workgroup which have the same state regarding security patches and other system updates. We recently found out that there is a problem with the NIReport.llb\Print HTML Report using IE.vi on the different machines.
    If I would open the VI on MachineA the control could be loaded. If I would open the VI on MachineB the control could be loaded. If I would copy the VI from MachineB to MachineA and open the VI the control could not be loaded. If I would copy the VI from MachineA to MachineB and open the VI on MachineB the control could be loaded. MachineB could load the version from MachineA and MachineB but on MachineA only the own version will load. I have seen that both versions have the same GUID for the Microsoft Webbrowser but are different in some other aereas.
    Since printing HTML Reports is part of the application which will be distributed as application I want to know if someone else have seen such a behaviour or has got problems distributing an application.
    Also I want to know which additional information is stored in an Active-X container about the control beside the GUID.
    We have Win XP Prof SP2 with MS IE 6.0.2900.2180 on all machines in the workgroup.
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions

    Hi Tom,
    this is the VI <vi.lib>\Utillitiy\NIReport.llb\Print HTML Report using IE.vi copied from a machine that can load and run the VI and it will print. On this machine the control in the VI is white.
    This VI will give the "Control could not be loaded" message on my machine.
    The file shdocvw.dll is 2006-10-23 16:18 size 1.460 KB and I verifyed that both machines have the same version of this file.
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions
    Attachments:
    Print HTML Report using IE.png ‏11 KB

  • How can I print a doc from my iPhone 4S to a Lexmark Interpret S405 printer with WiFi? Thanks!

    How can I print a doc from my iPhone 4S to a Lexmark Interpret S405 printer with WiFi? Thanks!

    Unfortunately you need an airprint enabled printer to print from an iOS device. There are some work arounds but they are very complicated and aren't proven to work 100%. From what I understand through rumors they are working on allowing all wireless printers to work with iOS but at the moment that's a pipedream. I don't know how important it is but if you really need to print from iPhone you can find some great AirPrint printers on Ebay for decent prices. Good Luck!

  • Is there a difference between saving a word doc with images as a pdf or printing to pdf?

    Is there a difference between saving a word doc with images as a pdf or printing to pdf. Images are sometimes missing when the document is  saved as a pdf or they are visible to the document owner but seem to disappear when viewed after submission to grants.gov. and proposal Central.
    Using Acrobat 9.5.5 and Office 2010 and Office 2011 Mac

    Is there a difference between saving a word doc with images as a pdf or printing to pdf. Images are sometimes missing when the document is  saved as a pdf or they are visible to the document owner but seem to disappear when viewed after submission to grants.gov. and proposal Central.
    Using Acrobat 9.5.5 and Office 2010 and Office 2011 Mac

  • Html doc to printer?

    I am having trouble finding out how to print(send to a printer) out html. I have tried java 1.4's Java print service, but get this error: sun.print.PrintJobFlavorException: invalid flavor, so it seems operation I am trying to do isn't supported. Have enyone an exaple how to print html?

    There is 1 way to do it on Windows, create a file from the application, then make the application run the spooler on the local PC with the location of the file, that should work.
    The other: about that PrintFlavor - does the class implement the PrintGraphics interface? It has to if it wants to print.
    Thats all I know for now.

  • Eprint printed .doc with a wrong size!!

    my printer is C310a
    when i printed my  A4 .doc document, it printed out with a wrong size and it's all of them are bigger than the actual size!
    Please help me to slove this.

    Hi jefferl,
    Welcome to the HP Support Forums.  I understand that when printing a .doc type document with your Photosmart C310a printer, that the font of document seems to be larger than requested.
    The font and its size are set by the program you are using and/or the program used to create the document. If you need to change the font and its size open the document in a program where you can edit the font. Mostly likely this document would have been created using Microsoft Word or Microsoft WordPad and you can use either of them to modify the font size.
    Regards,
    Happytohelp01
    Please click on the Thumbs Up on the right to say “Thanks” for helping!
    Please click “Accept as Solution ” on the post that solves your issue to help others find the solution.
    I work on behalf of HP

  • Print html document

    Hi, I'm trying to print a html document with this following java code but doesn't works:
      public void onActionPrintEncuestaPDF(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionPrintEncuestaPDF(ServerEvent)
         try{
              Robot robot = new Robot();
              // Ctrl+P
              robot.keyPress(KeyEvent.VK_CONTROL );          
              robot.keyPress(KeyEvent.VK_P );          
              robot.keyRelease(KeyEvent.VK_CONTROL);
              robot.keyRelease(KeyEvent.VK_P );
              Thread.sleep(500);
              //Alt+U
              robot.keyPress(KeyEvent.VK_ALT );
              robot.keyPress(KeyEvent.VK_U );
              robot.keyRelease(KeyEvent.VK_ALT );
              robot.keyRelease(KeyEvent.VK_U );
              Thread.sleep(500);
              //entrée
              robot.keyPress(KeyEvent.VK_ENTER);
              robot.keyRelease(KeyEvent.VK_ENTER );
              Thread.sleep(500);
         catch(Exception e){  }
        //@@end
    This is not working because java.awt.Robot is a part of AWT package and intended for the client site, how I can make an action that when the
    client push the print button. Print the html document automatly.
    Regards,
    Gabriel

    I create into KM Content on portal a file called print.html and I put the following code:
    &#65279;<html>
      <head />
      <body onLoad="window.parent.focus(); window.parent.print();">
      </body>
    </html>
    Because window.paren.print(); printed the code of actual iFrame. And into Web Dynpro I created a button that call the following function.
    public void onActionPrintEncuestaPDF(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
        //@@begin onActionPrintEncuestaPDF(ServerEvent)     wdContext.currentPrintElement().setAtrURL("/irj/go/km/docs/documents/print/print.html");
       //@@end

Maybe you are looking for

  • Bridge will not open, an error message is displayed regarding the cache.

    Hi,  when I try to open bridge I receive an error message with instructions to go to preferences and do something with the cache.  when I go to preferences, cache, purge cache everything freezes. the only way i can do anything is to force a shut down

  • Paid For

    Paid for and always asking me to pay again.  What's Up?

  • Bridge Tables

    Hi, I am having a little trouble using bridge tables. For testing I created an n-n relation. When I just make joins it shows the link table like fact table but queries work okay. When I check the bridge table check box, it identifies the correct fact

  • Mehrer Formularfelder auf ein Mal formatieren (Acrobat Pro XI)

    Hallo alle zusammen, ich habe hier 50 Formularfelder in einem PDF Dokument welches ich als "Währung mit € Zeichen" formatieren möchte. Gibt es eine Möglichkeit diese Formatierung auf alle 50 anzuwenden? Aktuell formatiere ich jedes Feld einzeln.

  • UAG SP3 Rollup 1 - Hotfix

    I have a UAG 2010 Array with 5 members for Direct-Access only. I'm needing to upgrade to SP4 to support Windows 8.1 DA clients and have a question about the Rollup 1. Do I need to go through the same process I used for a Service Pack - Upgrading the