Printing html text and font styles

Hello,
when I try to print html text in serif with italic or bold text style the output on a printer incorrectly shows the bold and italic parts in arial or something. Underlined text is printed correctly.
The font is rendered correctly on a JEditorPane.
There were some issues with html rendering in java (e.g. Bug IDs 4331766, 4160605, 1235430, 4141537) but as these bugs are closed/fixed in earlier jdk versions, and i found no hint that anyone else has experienced such problems, i may be doing something wrong?
Regards,
Dirk
My Configuration: Windows 2000 (German), JDK 1.5.0_12
For testing purposes i use the following:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.RepaintManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
* QDH (Quick and Dirty Hack) Test
public class PrintTestPane extends JEditorPane implements Printable {
   * shows printDialog and starts printing
  private void print() {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable( this );
    if ( job.printDialog() ) {
      try {
        job.print();
      catch ( Exception ex ) {
        ex.printStackTrace();
    else {
      System.out.println( "Aborted" );
   * from Printable Interface: renders a page
  public int print( Graphics graphics, PageFormat pageFormat, int pageIndex )
      throws PrinterException {
    Graphics2D g2 = (Graphics2D) graphics;
    RepaintManager.currentManager( this ).setDoubleBufferingEnabled( false );
    Dimension d = getSize();
    double panelWidth = d.width;
    double panelHeight = d.height;
    double pageWidth = pageFormat.getImageableWidth();
    double pageHeight = pageFormat.getImageableHeight();
    double scale = pageWidth / panelWidth;
    int totalNumPages = (int) Math.ceil( scale * panelHeight / pageHeight );
    // Check for empty pages
    if ( pageIndex >= totalNumPages )
      return Printable.NO_SUCH_PAGE;
    g2.translate( pageFormat.getImageableX(), pageFormat.getImageableY() );
    g2.translate( 0f, -pageIndex * pageHeight );
    g2.scale( scale, scale );
    print( g2 );
    return Printable.PAGE_EXISTS;
   * @param args
  public static void main( String[] args ) {
    PrintTestPane testPane = new PrintTestPane();
    HTMLEditorKit kit = new HTMLEditorKit();
    Document doc = kit.createDefaultDocument();
    try {
      kit.read( new ByteArrayInputStream( htmltext.getBytes() ), doc, 0 );
    catch ( IOException e ) {
      throw new RuntimeException( e );
    catch ( BadLocationException e ) {
      throw new RuntimeException( e );
    testPane.setContentType( "text/html" );
    testPane.setDocument( doc );
    JFrame frame = new JFrame();
    frame.getContentPane().add( testPane, BorderLayout.CENTER );
    frame.addWindowListener( new WindowAdapter() {
      public void windowClosing( WindowEvent event ) {
        System.exit( 0 );
    frame.pack();
    frame.setVisible( true );
    testPane.print();
  private static String htmltext = " <html> <head>  </head>  <body> <font face=\"serif\"> plain <b>bold</b> plain <i>italic</i> plain <u>underlined</u> plain</font> </body> </html>";
  private static final long serialVersionUID = 1L;
}

Hello again,
Update:
With JRE 6 it seems to work (at least with update 2). Because Java 6 is currently not an option for me: should i file a Bug?
Dirk

Similar Messages

  • Printing only Text and Subtotals lines in A/R Invoice not Regular lines

    How can I create in PLD for A/R invoice that only prints the Text and Subtotals lines in A/R Invoice but not the regular lines the A/R Invoice ?

    Hi Hector Santos,
    Try this,
    ->> Open the A/R Invoice Document.
    ->> Choose the Print Layout Design(PLD) on Top of the Menu Bar.
    ->> Open the A/R Invoice(System) PLD and Save as the New PLD.
    ->> Open the New PLD.
    ->> Choose the Database field(make) on Top of the Menu Bar.
    ->> Create the Database field in Repetetive Area.
    for example,
    Row Line Total Field:
    Table -> INV1 - A/R Invoice(Item).
    Column -> LineTotal.
    ->> Choose the TEXT field(make) on Top of the Menu Bar.
    ->> Create the TEXT field in Repetetive Area Footer or End of Report.
    ->> Create the Database field in Repetetive Area Footer or End of Report.
    for example,
    Document Total Field:
    Table -> OINV - A/R Invoice.
    Column -> DocTotal.
    This is Duplicate thread, so Close the thread.
    Regards,
    Madhan.

  • Change Background and font style in Web Page Composer ?

    Hi,
    someone knows how change the background and font style/size of the web page composer ?
    or how to control  font size style and background of WPC page using CSS ???
    point will  rwrd

    Hi,
    We are on EP7 SP14 and WPC SP14 Patch 2.
    Changing the css files should work perfectly...
    Try changing these files under the KM Content:
        KM Content -> root -> etc -> Web Content  -> css
    These are some of the css files that I have modified :
    root > etc > wpceditor > css > runtime > sdn_general.css
    root > etc > wpceditor > css > runtime > content.css
    root > etc > wpceditor > css > runtime > sdn_apps.css
    In particular, change the sdn_general.css and it will be changed.
    It works for us....

  • Keep getting an error message that reads, "LR An error has occurred while creating the book on Blurb" An error has occurred while trying to create texts and fonts.  Pleas advise as Blurb has said that it's a LR issue.

    Keep getting an error message that reads, "LR An error has occurred while creating the book on Blurb" An error has occurred while trying to create texts and fonts.  Pleas advise as Blurb has said that it's a LR issue.

    Are you behind a firewall or double NAT??
    What is the device that is immediately plugged into the main modem or router? Has that one been able to update?
    It is plugged in of course isn't it.. no nasty join wireless anywhere??
    The best way to work around these sort of problems is to simplify the network.. Plug each device directly into the main router.. by ethernet. You can trigger the firmware upgrade by wireless but use ipad or iphone version of airport utility and see what happens.

  • PS CS6  - text and font changes by clicking on it - not reversible

    Sometimes I open a file with layers in PS and click on a text layer, to move or change it,
    and immediately the text and font changes into another text/font from the document.
    Can not save the file then the problem stays forever. I can´t touch/change any text layer
    without this problem. Happens on every ca. 10th - 20th file  I open...
    Please help me, how can this be fixed?

    There was a bug in 13.0.0 that could corrupt text layers that way.
    It was fixed in 13.0.1, but documents saved with 13.0.0 could already be corrupted and there is no way to fix them automatically.

  • Font color and font style

    Can i know how can i change the color ,size and the style of the font in a text area?
    and also how can i get the font style and font size currently use in the text area?

    No, a Font doesn't have a colour. But you can set the colour of the text in a text area with setColor().

  • JTextPane, Selecting Text and Applying Styles

    Hello,
    Anyone encounter this situation? I have a mini word processor application that I have written using the RTFEditor kit and a JTextPane. To change style, e.g bold, font size, font face, etc, one can select text and then click a button or select a menu item. That part works fine. The styles are primarily changed by using the Action classes provided in the javax.swing.text.* package.
    The problem is, that if a user selected text of more than one style, all of the text is automatically converted to the style of the first part of the text selected, without the user even eanting to change ANY style just yet.
    If anyone knows why this might be happening I would surely appreciate it.
    Thanks,
    acal

    Solution to the style appling problem...
    public void actionPerformed( ActionEvent e )
            if (flag) return;
            if(e.getSource() == boldButton)
                SimpleAttributeSet attrs = new SimpleAttributeSet();
                attrs.addAttribute(StyleConstants.Bold,boldButton.isSelected());
                applyStyleToSelection(attrs);
                editorPane.grabFocus();
                return;
    public void applyStyleToSelection(AttributeSet attrs)
            int start = editorPane.getSelectionStart();
            int end = editorPane.getSelectionEnd();
            DefaultStyledDocument doc = (DefaultStyledDocument) editorPane.getDocument();
            doc.setCharacterAttributes(start, end - start, attrs, false);
            StyledEditorKit styled = (StyledEditorKit) editorPane.getEditorKit();
            MutableAttributeSet mas = styled.getInputAttributes();
            mas.addAttributes(attrs);
        }Filipi Silveira
    [email protected]

  • Arabic characters appear as empty squares when using certain HTML tags or font styles

    Only when HW acceleration is on. Arabic characters appear as empty squares when using "italic" or "oblique" font styles or when using &lt;i&gt; or &lt;em&gt; html tags.
    Try this code to replicate the problem
    <pre>
    &lt;p&gt;مشكلة ظهور المربعات الخالية بدل الحروف&lt;/p&gt;
    &lt;p style="font-style: italic;">Italic مشكلة ظهور المربعات الخالية بدل الحروف&lt;/p&gt;
    &lt;p style="font-style: oblique;">Oblique مشكلة ظهور المربعات الخالية بدل الحروف&lt;/p&gt;
    &lt;i&gt;i tag مشكلة ظهور المربعات الخالية بدل الحروف</i> &lt;br&gt; &lt;br&gt;
    &lt;em&gt;em tag مشكلة ظهور المربعات الخالية بدل الحروف &lt;/em&gt;
    </pre>

    After lots of research, I found the problem. The boxes (squares) show up whenever there is a font in the webpage that does not have Arabic within its Unicode range such as Times New Roman Italic or Oblique. Normally, Firefox will pick another font to display the characters but now, a newly introduced feature is interfering.
    To fix the problem without turning off hardware acceleration.
    Go to about:config
    locate: gfx.font_rendering.directwrite.use_gdi_table_loading
    which is True by default in FF4.0 Beta 10, and change it to False.
    This is a bug that has to be fixed.

  • Line wrapping and font styles?

    Hi,
    If I have a piece of text which I would like to see line wrapped, and font styled, how should I do that?
    javax.swing.JTextArea has the capabilities to set line wrapping to on.
    javax.swing.JTextPane has the capabilities to set font styles like bold, italic and so on.
    But what if you have a piece of text you don't know the (possible) length of (so you would like to have line wrapping), AND to which you want to apply font styles to. JTextArea and JTextPane are siblings, not ancestors. So I can't use it. I have looked in the code to see if I could use pieces of code in my own program. But not luck.
    Do you have a suggestion for me?
    TIA,
    Abel

    camickr wrote:
    JTextPane wraps by default. I'm not sure what your problem is.I did not know that JTextPane did wrap. And I could not find it in the documentation.
    But thanks for the information!

  • How to print html text created with HTML Editor Standard?

    I would like to print the text I added with the HTML Editor Standard, using advanced printing. I have made up a Word document with a Report Query and a Report Layout, but the text pops up as html text. Also when I use HTML as output the text shows as "p strong hallo /strong /p" (but then with < and >) instead of hallo . I understand what goes wrong, but I am unable to solve it. Is there a way to work around this?
    Thanks a lot, Frits
    Edited by: user3829016 on 10-nov-2009 5:51
    Edited by: user3829016 on 10-nov-2009 5:52
    Edited by: user3829016 on 10-nov-2009 5:53

    Thanks Lilly a lot!
    I forgot about this tag. It helps in my situation.
    P.S. I tried to solve problem with help of tag <pre> in such way:
    some_word<pre>     </pre>some_wordBut it didn`t helped.
    Thank you again

  • Flash Application Font-Face and Font-Style

    This is a similar thread to one I posted earlier but this one is
    more detailed to explain my problem
    Does anyone know how to change the programs font-face,
    font-size, font-style etc ... of the console? I'm referring to all
    of the outer workspace area, not the stage.
    I found the image below at some website by google just to
    illustrate:
    http://cis2.stvincent.edu/martincc/introwpd/flash/flashscreen.jpg
    See the panels on the right side?
    Swatches, Character, Sound panels. On my computer, the font
    size for these words and for everything inside these panels are
    microscopic. They are so small it can't be read unless you stare at
    it for a while.
    How do I change the font size or face for these fonts?
    Now you see the top of the screen, where it says "
    File Edit View Insert Modify Text Control Window Help"? All
    of these font sizes are perfectly normal just like everything on my
    computer. I also use Adobe Photoshop CS 8.0 and the panel window
    fonts are perfect as well as everything else, so I know that it is
    a problem only with my Flash 5.0.
    I would appreciate any help you guys can give me, as it takes
    me forever to work on a project, I have to stare for a while to
    figure out what the panel text says.

    anyone have any ideas on how to change the window panel text
    size?

  • Import Html text and convert to InDesign tags

    Hello everybody,
    The script receives a JSON with text (html markup: headers <h1>, <b></b>, new line characters, ...).
    I have to save the converted text into a temp text file and then do .place() into a text frame. That's the only way it can recognise new tags.
    //text and contentArea are defined previously.
    var convertedText = convertTags(text);
    var convertedTextFile = new File (FILE_PATH + "/Temp/convertedTextFile.txt");
    convertedTextFile.open('wr');
    convertedTextFile.write(convertedText);
    convertedTextFile.close();
    contentArea.place(convertedTextFile);
    function convertTags(htmlTaggedText){              
         var inDesignTaggedText = "<ASCII-MAC>\n" + htmlTaggedText.replace("<h1>", "<ParaStyle:Heading 1>").replace("</h1>", "");
         return inDesignTaggedText;
    General question is, whether there is any more elegant solution to this?
    Thanks in advance

    Hello everybody,
    The script receives a JSON with text (html markup: headers <h1>, <b></b>, new line characters, ...).
    I have to save the converted text into a temp text file and then do .place() into a text frame. That's the only way it can recognise new tags.
    //text and contentArea are defined previously.
    var convertedText = convertTags(text);
    var convertedTextFile = new File (FILE_PATH + "/Temp/convertedTextFile.txt");
    convertedTextFile.open('wr');
    convertedTextFile.write(convertedText);
    convertedTextFile.close();
    contentArea.place(convertedTextFile);
    function convertTags(htmlTaggedText){              
         var inDesignTaggedText = "<ASCII-MAC>\n" + htmlTaggedText.replace("<h1>", "<ParaStyle:Heading 1>").replace("</h1>", "");
         return inDesignTaggedText;
    General question is, whether there is any more elegant solution to this?
    Thanks in advance

  • How to print basic text and serial number

    HI,
          In invoice, I printed serial number and basic text in the second colum like this order...
    first row....SERIAL NUMBER
    second row...BASIC TEXT.
    now I want to print in the reverse order what I will do Please Explain clearly
    output:
    BASIC TEXT
    SERIAL NUMBER
    Thanks and Regards,
    surya

    Figured it out!  Thanks anyway!

  • Search for text and font

    I have an 800 page pdf document to index and so far I have a script that will search for a list of keywords. But the text has large sections of code in a different font, and I think we would like to generate an index of just code examples. Is there a way to search for text of a given font in applescript? Something like
    set theSel to find text theText
    if the font of theSel is "Times"
    write to file, etc.

    Please do send a page, I might be able to spot where the font problem is coming from - but no guarantee Address is in my profile.
    You asked about the script formatter. red_menace of this forum wrote the script I use. To use it, you copy the script that you want to format to the clipboard and run the formatter. This then places the marked-up text in the clipboard so that you can paste it into the forum page.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;">
    script formatter - formats the clipboard text for forum posting
    last reviewed January 19, 2009   red_menace[at]mac[dot]com
    Input: text read from the clipboard
    Output: formatted text copied to the clipboard
    set AppleScript's text item delimiters to " "
    -- some constants and switches
    property TextColor : "#000000" -- black  (see http://www.w3schools.com/tags/ref&#95;colornames.asp)
    property BackgroundColor : "#FFDDFF" -- a light plum/purple
    property BorderColor : "#000000" -- black
    property TheWidth : "width: 720px; " -- a width attribute  (deprecated in HTML 4.01)
    property UseWidth : true -- use the width attribute?
    property LineCount : 25 -- the number of lines before including the height attribute
    property TheHeight : "height: " & ((LineCount * 13.6) as integer) & "px; " -- a maximum height for the <pre> box
    property Emphasize : false -- emphasise (bold) the script text?
    property UseURL : false -- include a Script Editor message link?
    property AltURL : false -- use an alternate URL encoding?
    property ToolTips : {¬
    "this text can be pasted into the Script Editor", ¬
    "this text can be pasted into an Automator 'Run AppleScript' action", ¬
    "this text can be pasted into an Automator 'Run Shell Script' action", ¬
    "this text can be pasted into a HTML editor", ¬
    "this text can be pasted into a text editor", ¬
    "- none -"}
    property TooltipDefault : {item 1 of ToolTips} -- keep track of the last tooltip used
    property TempFile : "Script_Formatter_TempFile" -- a temporary work file
    try
    -- write the clipboard to the temporary file
    set TheClipboard to (the clipboard) as text
    if TheClipboard is in {"", space, tab, return} then return -- clipboard is (basically) empty
    set MyOpenFile to open for access ("/tmp/" & TempFile & ".txt" as POSIX file) with write permission
    set eof of MyOpenFile to 0 -- empty any previous temp file
    write TheClipboard to MyOpenFile
    close access MyOpenFile
    if UseURL then
    -- encode URL  (see http://developer.apple.com/documentation/Darwin/Reference/Manpages/man1/pydoc.1. html)
    do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of TheClipboard
    -- add a link wrapper
    set URLtext to "applescript://com.apple.scripteditor?action=new&script=" & the result
    if AltURL then -- use an alternate URL encoding
    set URLtext to "Click here to [url=" & URLtext & "]open this script in the Script Editor[/url]:<br />"
    else -- use HTML anchor tag
    set URLtext to "Click here to <a href=\"" & URLtext & "\">open this script in the Script Editor</a>:<br />"
    end if
    set PromptText to ((count URLtext) as text) & " URL and "
    else
    set {URLtext, PromptText} to {"", ""}
    end if -- UseURL
    -- convert to HTML  (see http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/textutil .1.html)
    do shell script "cd /tmp/; /usr/bin/textutil -convert html -excludedelements '(html, head, title, body, p, span, font)' -encoding US-ASCII " & TempFile & ".txt"
    -- fix up some formatting and add a pre wrapper  (see http://www.w3schools.com/tags/default.asp)
    set HTMLtext to rest of paragraphs of (read ("/tmp/" & TempFile & ".html" as POSIX file))
    if (count HTMLtext) is less than LineCount then -- skip the height attribute
    set Height to ""
    else
    set Height to TheHeight
    end if
    set HTMLtext to FixCharacters from (HTMLtext as text) -- additional character encodings
    if UseWidth then
    set Width to TheWidth
    else
    set Width to ""
    end if
    if Emphasize then set HTMLtext to "<strong>" & HTMLtext & "</strong>"
    set HTMLtext to "<pre style=\"
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid " & BorderColor & ";
    " & Width & Height & "
    color: " & TextColor & ";
    background-color: " & BackgroundColor & ";
    overflow: auto;\"
    title=\"\">
    " & HTMLtext & "</pre>
    -- assemble everything on the clipboard
    set TheResult to choose from list ToolTips ¬
    with title "Script Formatted" with prompt PromptText & ((count HTMLtext) as text) & " HTML characters will be placed on the clipboard (plus the following ToolTip):" default items TooltipDefault OK button name "OK" cancel button name "Cancel" with empty selection allowed without multiple selections allowed
    if TheResult is false then -- cancel button
    error number -128
    else -- add the selected title attribute (tooltip), if any
    set TooltipDefault to TheResult as text
    set Here to (offset of " title=" in HTMLtext) - 1
    set There to (offset of ">" in HTMLtext) - 1
    if TheResult is in {{}, "- none -"} then -- no tooltip
    set the clipboard to URLtext & (text 1 thru (Here - 1) of HTMLtext) & (text (There + 1) thru -1 of HTMLtext)
    else
    set the clipboard to URLtext & (text 1 thru (Here + 9) of HTMLtext) & TheResult & (text There thru -1 of HTMLtext)
    end if
    end if -- TheResult is false
    on error ErrorMessage number ErrorNumber
    log space & (ErrorNumber as text) & ":" & tab & ErrorMessage
    try
    close access MyOpenFile
    end try
    if (ErrorNumber is -128) or (ErrorNumber is -1711) then -- nothing (user cancelled)
    else
    activate me
    display alert "Error " & (ErrorNumber as text) message ErrorMessage as warning buttons {"OK"} default button "OK"
    end if
    end try
    to FixCharacters from TheText
    fixes (converts) formatting characters used in some message forums  (see http://www.asciitable.com/)
    parameters - TheText [text]: the text to fix
    returns [text]: the fixed text
    -- this list of lists contains the characters to encode - item 1 is the character, item 2 is the HTML encoding
    set TheCharacters to {¬
    {"!", "&#33;"}, ¬
    {"*", "&#42;"}, ¬
    {"+", "&#43;"}, ¬
    {"-", "&#45;"}, ¬
    {"[", "&#91;"}, ¬
    {"\\", "&#92;"}, ¬
    {"]", "&#93;"}, ¬
    {"^", "&#94;"}, ¬
    {"_", "&#95;"}, ¬
    {"~", "&#126;"}}
    set TempTID to AppleScript's text item delimiters
    repeat with SomeCharacter in TheCharacters
    if item 1 of SomeCharacter is in TheText then -- replace
    set AppleScript's text item delimiters to item 1 of SomeCharacter
    set the ItemList to text items of TheText
    set AppleScript's text item delimiters to item 2 of SomeCharacter
    set TheText to the ItemList as text
    end if
    end repeat
    set AppleScript's text item delimiters to TempTID
    return TheText
    end FixCharacters
    </pre>

  • Htp.p packages and font styles

    How to I add underline style to this? And single spacing for the next paragraph?
    htp.p('<p><font size="25" color="green" style="font-weight:bold";>Document Control</font></p>');I've tried incorporating this to no avail:
    htp.p('<p><font size="25" color="green" style="font-weight:bold"; text-decoration: underline;>Document Control</font></p>');

    Hi,
    Do not use FONT tag it is deprecated
    http://www.w3schools.com/tags/tag_font.asp
    Try
    htp.p('&lt;p style="font-size:25px;color:green;text-decoration: underline;">Document Contro&lt;/p>');Regards,
    Jari

Maybe you are looking for

  • BSI upgrade from 8.0 to 9.0

    Hi Experts, New BSI Tax factory 9.0 has been released recently. I would like to know what are the steps needed to upgrade tax factory from 8.0 to 9.0. I have gone through SAP Note 1469858 for details and found that major activities are related to bas

  • How does one rename or even delete templates in Pages?

    How does one rename or even delete templates in Pages?

  • Internal Table Logic Needed

    Hi all, I have a requirement regarding data processing in a internal table, internal table consists of filelds Vendor,Material and Scheduling Dates and Total Qty. Here i need to fill the field Total Quantity, individual addition of quanties of that m

  • KEYBOARD PROBLEM ON MODEL G450

    I HAVE A LENOVO G450 LAPTOP WITH WINDOWS 7 ON IT.  EVERYTHING WORKS FINE UNTIL I LOG INTO MY COMPANY'S DATACOR ERP SOFTWARE.  NO MATTER IF IM CONNECTED VIA HARD WIRE OR WIFI,  WHEN I USE THE KEYBOARD THE NUMBERS DO NOT WORK PROPERLY.  I HAVE TO HIT F

  • Table control data in color

    Hi Experts,    My table control having 3 materils as below . MATNR      MTART    WERKS 222             AA         1000 333             BB          1108 444             CC          1200 Client requirement is to display material-333 in red font color,