RTF Printing in J2SE 5

Hi,
We are experiencing problems with printing RTF documents in J2SE 5. Our applications prints as expected on J2SE 1.4 but running the same application on J2SE results in output that is looking akward since character spacing is wrong.
I have created a small sample application to show the problem. Compile it for J2SE 1.4 and run it using both version 1.4 and 5 and compare the output.
Does anyone know about any changes in J2SE 5 that should cause this behaviour - or perhaps someone could spot the problem? Any help would be appreciated.
SAMLE APPLICATION:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.print.*;
import javax.swing.plaf.basic.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.text.rtf.*;
import javax.swing.undo.*;
public class RTFExample {
    private static final String RTF = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1030{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}}\\viewkind4\\uc1\\pard\\sb100\\sa100\\f0\\fs22 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam tortor nunc, elementum quis, tincidunt non, lacinia non, sapien. Cras pulvinar, ipsum sed imperdiet tristique, justo felis eleifend felis, eget porttitor nunc nisl vel sapien. Vestibulum eu quam quis nisl feugiat sagittis. Quisque convallis. Cras pede. Mauris risus nisi, tincidunt ut, vehicula quis, posuere in, elit. Mauris tempus leo ut mi. Nulla non sem. Suspendisse nec eros vitae turpis condimentum pulvinar. Fusce tortor lacus, egestas gravida, mollis et, ornare et, augue. Nulla consequat, turpis id fermentum tincidunt, turpis nunc facilisis libero, ut consectetuer diam lorem nec enim. Sed quis urna. In vel felis eget nibh semper porttitor. Nulla convallis consequat quam. Suspendisse at ipsum eget tortor vestibulum pellentesque. In hac habitasse platea dictumst. Pellentesque in sem sed dolor laoreet volutpat. Curabitur eleifend lobortis sapien. Vivamus tellus sem, consequat at, suscipit adipiscing, dapibus non, magna. Sed quam purus, faucibus quis, molestie ac, commodo a, tortor.\\par}";
    public static void main(String[] args) {
     GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
     RTFExample t = new RTFExample();
     t.printData();
    public void printData() {
     try {
         TestRTFRenderer renderer = new TestRTFRenderer();
         JTextPane tp = new JTextPane();
         renderer.setpane(tp);
         EditorKit rtfek = tp.createEditorKitForContentType("text/rtf");
         tp.setEditorKit(rtfek);
         StyleContext ctx = new StyleContext();
         DefaultStyledDocument d = new DefaultStyledDocument(ctx);
         tp.setDocument(d);
         rtfek.read(new StringReader(RTF), d, 0);
         PrinterJob prnJob = PrinterJob.getPrinterJob();
         PageFormat format = prnJob.pageDialog(prnJob.defaultPage());
         prnJob.setPrintable(renderer, format);
         if (prnJob.printDialog() == false) {
          return;
         prnJob.print();
     } catch (Exception e) {
         e.printStackTrace();
class TestRTFRenderer implements Printable {
    // This external class that does all the printing of all the rtf document pages
    int currentPage = -1;
    JTextPane jtextPane = new JTextPane();
    double pageEndY = 0;
    double pageStartY = 0;
    boolean scaleWidthToFit = true;
    int currentIndex = 0;
    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
     // This function is the main printable overided function
     double scale = 1.0;
     Graphics2D graphics2D;
     View rootView;
     graphics2D = (Graphics2D) graphics;
     jtextPane.setSize((int) pageFormat.getImageableWidth(), Integer.MAX_VALUE);
     jtextPane.validate();
     // I think the error is somwhere here
     rootView = jtextPane.getUI().getRootView(jtextPane);
     if ((scaleWidthToFit) && (jtextPane.getMinimumSize().getWidth() > pageFormat.getImageableWidth())) {
         scale = pageFormat.getImageableWidth() / jtextPane.getMinimumSize().getWidth();
         graphics2D.scale(scale, scale);
     // The below four command lines shows that the content is clipped
     // to the size of the printable page
     graphics2D.setClip((int) (pageFormat.getImageableX() / scale), (int) (pageFormat.getImageableY() / scale), (int) (pageFormat.getImageableWidth() / scale), (int) (pageFormat.getImageableHeight() / scale));
     // The below if statement is to check to see if there is a new page to render
     if (pageIndex > currentPage) {
         currentPage = pageIndex;
         pageStartY += pageEndY;
         pageEndY = graphics2D.getClipBounds().getHeight();
     graphics2D.translate(graphics2D.getClipBounds().getX(), graphics2D.getClipBounds().getY());
     Rectangle allocation = new Rectangle(0, (int) -pageStartY, (int) (jtextPane.getMinimumSize().getWidth()), (int) (jtextPane.getPreferredSize().getHeight()));
     // The below if else statements return PAGE_EXISTS only if the class
     // sees that there are some contents in the document by calling the printView class
     if (printView(graphics2D, allocation, rootView)) {
         return PAGE_EXISTS;
     else {
         pageStartY = 0;
         pageEndY = 0;
         currentPage = -1;
         currentIndex = 0;
         return NO_SUCH_PAGE;
    protected boolean printView(Graphics2D graphics2D, Shape allocation, View view) {
     // This function paints the page if it exists
     boolean pageExists = false;
     Rectangle clipRectangle = graphics2D.getClipBounds();
     Shape childAllocation;
     View childView;
     if (view.getViewCount() > 0) {
         for (int i = 0; i < view.getViewCount(); i++) {
          childAllocation = view.getChildAllocation(i, allocation);
          if (childAllocation != null) {
              childView = view.getView(i);
              if (printView(graphics2D, childAllocation, childView)) {
               pageExists = true;
     else {
         // The below if statement checks if there are pages currently to paint
         if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {
          pageExists = true;
          if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) && (allocation.intersects(clipRectangle))) {
              view.paint(graphics2D, allocation);
          else {
              if (allocation.getBounds().getY() >= clipRectangle.getY()) {
               if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY() - 15) {
                   view.paint(graphics2D, allocation);
               else {
                   if (allocation.getBounds().getY() < pageEndY) {
                    pageEndY = allocation.getBounds().getY();
     return pageExists;
    public void setpane(JTextPane TextPane1) {
     // This function gets the JTextPane
     jtextPane.setContentType("text/rtf");
     jtextPane = TextPane1;
}

mpogra, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
I'm locking this thread now.
db

Similar Messages

  • Printing with J2SE 1.4 Printing API

    Hi Everyone,
    Is there any tutotial or any type of documentation that talks about how to use J2SE v.1.4 Printing API. I've heard that it's much simpler and easier to use than old AWT printing API.
    Thanks in advance,
    YM

    do NOT cross post

  • Call Stylesheet from RTF file

    Hi
    I’m working using EBS.
    We have an Oracle template to print the RFQs using stylesheet (xsl file)
    One of the requirements is to add five pages before the RFQ is printed.
    My problem is: How can I from a RTF print my first pages, go to stylesheet and print the RFQ?
    What I did:
    I have created a template “supp” in the Stylesheet; in this template I call the root in the stylesheet
    I created a RTF to create my 5 pages and import the Stylesheet
    I’m able to call the new template supp in the Stylesheet
    After that the RTF didn’t print anything and it generates and exception.
    I appreciate any help.
    Many thanks,
    Alex

    http://www.apps2fusion.com/forums/viewtopic.php?f=60&t=533
    http://winrichman.blogspot.com/
    http://winrichman.blogspot.com/2008/09/using-xsl-template-eliminate-carrigae.html
    http://winrichman.blogspot.com/search/label/BIP%20Call%20templates

  • .DOC output from Documaker 11.5 ?

    Hi,
    Can any one tell me how to generate .DOC output from Documaker like .PDF ?
    We need to change in INI settings. I tried and generated .DOC file but when i opened all are Junk characters in the Word document.
    Please help what changes exactly we need to make in INI files ?
    Note: I have tried generating .RTF format in the output.That's working fine. Then why not .doc ?
    Thanks & Regards,
    RAMAN C
    Edited by: 969704 on Jan 8, 2013 3:39 AM

    There are a lot of options with the RTF Print Driver in Documaker and new features in 12.0 and 12.1. Be sure to review the documentation. To see what's available in 12.1 see the Printers Reference at http://docs.oracle.com/cd/E22582_01/printers_rg.pdf.
    -DA

  • Print Quote the report is in PDF but need to be new RTF template

    We have 11.5.10 apps, the Quote screen is an OAF screen.
    When clicking Print Quote the report is in PDF, They want to include a new RTF template for printing instead of PDF.
    The new RTF template is created. But what I do not know is how the quote screen will take the new template. I can use XMLP to upload the RTF template but that may not be sufficient to make it appear in the Quote screen.
    I am looking at the profile ASO:Default Layout Template. Am I headed the right way?

    Hi,
    Please refer to the following documents, it should be helpful.
    Note: 780722.1 - How to Create a Custom Print Quote Template in Oracle Quoting ?
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=780722.1
    Note: 392728.1 - How to Modify the data source for the XML version of the Print Quote report
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=392728.1
    Note: 468982.1 - How To Customize The Asoprint.Xsl
    https://metalink2.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=468982.1
    Regards,
    Hussein

  • To upload a RTF and a PDF file to SAP R/3 and print the same through SAP

    Hi,
    I have a requirement to upload a PDF file and a RTF file to SAP R/3 and print the same.
    I wrote the following code for uploading a RTF file to SAP R/3 and print the same. However, the problem is , the formatting present in the RTF document( bold/italics..etc) is not being reflected when I do the 'print-preview' after the executing the code below :
    report z_test_upload .
    data: begin of itab occurs 0,
             rec type string,
          end of itab.
    data: options like itcpo.
    data: filename type string,
          count type i.
    data: filetype(10) type c value 'ASC'.
    DATA: HEADER  LIKE THEAD    OCCURS   0 WITH HEADER LINE.
    DATA: NEWHEADER  LIKE THEAD    OCCURS   0 WITH HEADER LINE.
    DATA: ITFLINE LIKE TLINE    OCCURS   0 WITH HEADER LINE.
    DATA: RTFLINE LIKE HELP_STFA OCCURS   0 WITH HEADER LINE.
    DATA:   string_len TYPE i,
            n1 TYPE i.
    selection-screen begin of block b1.
      parameter: p_file1(128) default 'C:\test_itf.rtf'.
    selection-screen end of block b1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
      CALL FUNCTION 'F4_FILENAME'
           IMPORTING
                file_name = p_file1.
    start-of-selection.
    move p_file1 to filename.
    call function 'GUI_UPLOAD'
         EXPORTING
              filename                = filename
              filetype                = filetype
         TABLES
              data_tab                = itab
         EXCEPTIONS
              file_open_error         = 1
              file_read_error         = 2
              no_batch                = 3
              gui_refuse_filetransfer = 4
              invalid_type            = 5
              no_authority            = 6
              unknown_error           = 7
              bad_data_format         = 8
              header_not_allowed      = 9
              separator_not_allowed   = 10
              header_too_long         = 11
              unknown_dp_error        = 12
              access_denied           = 13
              dp_out_of_memory        = 14
              disk_full               = 15
              dp_timeout              = 16
              others                  = 17.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    loop at itab.
      string_len = strlen( itab-rec ).
      n1 = string_len DIV 134.
      ADD 1 TO n1.
      DO n1 TIMES.
        rtfline-line = itab-rec.
        APPEND rtfline.
        SHIFT itab-rec BY 134 PLACES.
      ENDDO.
    endloop.
    HEADER-TDSTYLE = 'S_DOCUS1'.
    HEADER-TDFORM = 'S_DOCU_SHOW'.
    header-tdspras = 'E'.
    CALL FUNCTION 'CONVERT_TEXT'
      EXPORTING
      CODEPAGE               = '0000'
        DIRECTION              = 'IMPORT'
        FORMAT_TYPE            = 'RTF'
       FORMATWIDTH            = 72
        HEADER                 = header
        SSHEET                 = 'WINHELP.DOT'
        WITH_TAB               = 'X'
        WORD_LANGU             = SY-LANGU
        TABLETYPE              = 'ASC'
      TAB_SUBSTITUTE         = 'X09  '
      LF_SUBSTITUTE          = ' '
      REPLACE_SYMBOLS        = 'X'
      REPLACE_SAPCHARS       = 'X'
      MASK_BRACKETS          = 'X'
      IMPORTING
        NEWHEADER              = NEWHEADER
      WITH_TAB_E             =
      FORMATWIDTH_E          =
      TABLES
        FOREIGN                = RTFLINE
        ITF_LINES              = ITFLINE.
      LINKS_TO_CONVERT       =
    if sy-subrc <> 0.
    endif.
    CALL FUNCTION 'PRINT_TEXT_ITF'
      EXPORTING
         HEADER        = newheader
         OPTIONS       = options
    IMPORTING
      RESULT        =
      TABLES
        LINES         = itfline.
    if sy-subrc <> 0.
    endif.
    Any hints or suggestions to solve this problem will be highly appreciated.
    Thanks,
    Avra

    Hi Vishwas,
    Check out the thread [Efficient way of saving documents uploaded|Re: Efficient way of saving documents uploaded by users; and check the blog by Raja Thangamani.
    Also check the thread [Export Images through Function Modules   |Export Images through Function Modules;.
    Hope it helps you.

  • In BI Publisher RTF table layout issue for invoice printing

    Hi,
    I am working on check printing and invoice printing project on bi publisher and i am facing one issue. That is i have used section break on check priting so because of that if the the records are more than 20 then check will print on second page and on first page there would be void printed othervise it should print on first page only. In this case the preprinted stationary is not having invoice table form. we are using blank preprinted stationary to print this .
    Now i have done with invoice and cheque layout but in output if the number of records are more than 20 then its going to second page but the problem is that invoice table break into two parts and and the end lineof table layout is not coming on first page .even on second page i am not getting start layout line to make complete table outline.
    I want that full table layouton both the pages of the table. i have tried to to create table skeleton and used it as a watermark to print all the records on it but it is coming in to the middle of the page .so it not working.
    Please anyone knows the solution on this problem please let me know or share your thoughts on this issue.
    As i have tried many options but still stuck into this issue .Kindly help me.
    Regards,
    Prachi G.

    Hmmm ... sounds like a regression bug.
    I would contact support, provide, the version you are using, layout template, sample XML data, 2000 RTF output and 2003 RTF output and ask them to investigate.
    Tim

  • R12 - check printing : How to set RTF template for preprinted stationary

    Hi all,
    We are on R12 instance and have requirement of check printing on preprinted stationary. For this requirement we are customizing standard RTF template.
    Preprinted stationary layout is like upper part ( check nmber, check date) then body part ( invoices details ) and then trailer part ( check amount, supplier name)
    Problem: When I am printing check against only one invoice then print is coming properly but if I print check against more than one invoice then trailer part (check amount, supplier name) is moving forward. I want trailer part to be fixed on same position.
    If anyone have already done this please guide me.
    Thanks n advance,
    Mandar
    Edited by: MS on Aug 26, 2010 8:29 AM

    Try to put them in a Table Columns.
    I Hope they will not move...
    Thanx,
    Deepak

  • New RTF Template for Quote Print

    Hi,
    Oracle has provided only XSL Template for Quote Printing. Since Client needs his own format of Quote Printing, Can we create a new Customized RTF template for Quote Printing? or Is there any easy way to do customize the XSL Template?
    Pls advise..
    Thanks in advance,
    Regards,
    Muru
    Message was edited by:
    Muru

    Hi Miru,
    I need ur help.I am working on the same customization of xsl template.can u please guide me through how to work with this.
    I need to customize print quote report
    Can u please tell me the link/steps how to customize the jsp form to replace the standard CP with custom one
    Secondaly,which one option is better ,creating a new rtf/modifying the existing xsl
    and how ?as i dont have any idea about xsl.but i know creatig rtf's
    Please guide me thru.
    Thanks a ton in advance
    kaur

  • To attach a RTF template(Report for printing ) in the master detail form

    I have an application in which I have 3  master detail forms  of which one of the form is a gate pass form . Now this gate pass form has a report region as the detail.
    All that i need help is to print the Gate Pass with few fields as information in the gate pass form , where an image or picture of the visitor is also a filed .
    Now I have created an RTF Template  which is the Gate pass layout with the pic.
    So ultimately I have the application for the gate pass form and the RTF template ready with me .. Fixing this template with the application with a BUTTON called PRINT is the challenge am facing !
    SELECT XVH.GPDATE
           , TO_CHAR(XVH.VISITORTIMEIN, 'HH:MI') VISITORTIMEIN --, (XVH.VISITORTIMEIN )
           , (TO_CHAR(XVH.VISITORTIMEOUT, 'HH:MI'))VISITORTIMEOUT
           , XVH.VISITOR_NAME --, = XVH.PERSON_ID
           , XVH.COMAPANY_NAME
           , XVH.PURPOSE_OF_VISIT
           , (SELECT A.FULL_NAME
                FROM PER_ALL_PEOPLE_F A
               WHERE A.PERSON_ID = XVH.PERSON_ID
                 AND SYSDATE BETWEEN A.EFFECTIVE_START_DATE AND A.EFFECTIVE_END_DATE) To_meet
           , XVH.VISITOR_PHONE
           ,APPS.GETBASE64 (XVH.VISITOR_PHOTO)
      FROM xxcdot.XXBCT_VGPF_HEADER XVH
    WHERE XVH.GP_HEADER_ID =  :P_HEADER_ID
    This is the query for the template ..
    Please help me with this. I am very new to apex and learning it with help of online tut

    Pars I need another Help
    I am working with a master detail form where in the form region i have a Radio group . Lets say the Radio group is
    o Returnable
    o Non Returnable
    o Other
    so when i select Non returnable I want a particular column called
    Line Status to get Disabled .
    I have done that by a dynamic action - using jquery statement (.Disable) .
    Defining the element attributes as Disable .
    Now the problem is that ,, Line status is getting disabled on the selection of Non returnable radio button. but unless and until i dont press the Add row button it does not work ,, else i will have to switch over between the radio buttons to get this action done !!

  • How to print multiple footers for each page in RTF template xml report.

    Hi,
    How to print multiple footers for each page in RTF template xml report.
    i am able to print ( two sets ) ...
    up to last page ( one template ) and for last page ( another template).
    i want to change the footer information based on the group value printed in the report ( it might be 5 to 6) In every report run.. can you please check and let me know do we have any feasibility to achieve this.
    Thanks in advance.
    Regards,
    KAP.

    You can remove all other logic, like last page only contents (start@last-page:body), etc and section breaks if any you have inserted manually.
    Just have for-each@section logic.
    It would be difficult for me to guess what you have done without looking at your RTF or describing here.

  • Printing problem with RTF file in java

    Hi,
    i actually got code to print the RTF doc using java, it works fine if we give small content (some text), but throws error 'java.io.ioException: Too many close-groups in RTF " when actual bill content is pass.
    Thanks in advance

    Can you please share the code to print the RTF file using java API

  • Problems with check printing RTF template

    To BI Publisher Gurus,
    I am working on the check printing RTF template and facing a few issues with page breaks, filling the insufficient invoice lines with template and positioning of the table(s) itself inside the RTF template.
    For page break, am using the following piece of code just before the end of all of my FE loops.
    <xsl:if xdofo:ctx="inblock" test="position()-1<count($inner_group)"><xsl:attribute name="break-before">page</xsl:att:attribute></xsl:if>
    the $inner_group is my group for G_INVOICES to loop through all the invoices of a check in G_CHECKS group.
    The problem I'm facing is, everytime a check is printed its printing a blank page in between. Searched all the earlier forum posts but none of the solutions worked in my case.
    Second issue, for filling the insufficient invoice lines (in my case, am printing 26 invoices per page per check), the call to the blank lines template is repeating twice and found no way to get rid of it.
    Third issue, if the check is running into a second page, the call to the blank lines template does not work and the position of the bottom part of check is getting misaligned.
    I am ready to send my template and the sample XML file to look at. Thanks for your time and effort.
    -Uday

    Hi Tim,
    Hi Tim,
    Could you please send me the sample rtf. We are also using APXPBFEG program for check printing..
    Also I have problem in generating dots(....) in the check where if total invoices lines are 37 and we have only one line of invoice then I have to generate 36 dots (.) in the invoice porition of the check..
    I appreciate your help..
    Thanks
    Krishna
    [email protected]

  • Printing Header and Footer once in HTML and on all pages in RTF and PDF using one RDF

    Hi,
    I am using a single RDF to generate reports in HTML,PDF and RTF.
    For printing the header only on the first page I used the
    following trigger
    begin
    srw.get_page_num (page_num);
    IF upper(:P_FORMAT) = 'HTML' THEN
    if page_num = 1 then
    return(true);
    else
    return (FALSE);
    end if;
    ELSE
    return (TRUE);
    END IF;
    end;
    I alo require to print the footer once on the last page in case
    of HTML and on all pages for RTF and PDF.Is there any way I can
    get the total number of pages or is there any other way to
    acheive this. ???
    Any help would be appreaciated .
    Thanks,
    Alka

    Generally, one template can not create nice output in all formats. In your case, you would need a format parameter to suppress headers/footers if it's value is 'EXCEL'. The problem is (I wish someone would correct me on this) that we can not refer the standard parameter already there and have to create another, user-defined parameter.

  • How can I get the template( word rtf )  for PO – Printed Purchase Order ?

    I want to convert the “PO - Printed Purchase Order” report from Oracle rdf format to BI Publisher. I am looking for the template but could not find in UNIX.
    As per the Oracle blog, the template is available. Please see the URL : https://blogs.oracle.com/xmlpublisher/resource/121BIPReports.pdf
    The template code is POXPRPOL_XML.rtf
    when I look at the $PO_TOP/patch/115/publisher/templates/US directory, I cannot find POXPRPOL_XML.rtf
    How can I get the template( word rtf ) for PO – Printed Purchase Order ?
    Thank you,
    Biju Varghese.

    How can I get the template( word rtf ) for PO – Printed Purchase Order ? XML Publisher Administrator -> Templates
    find by code or name
    open it and you can downloadtemplate by "download" button

Maybe you are looking for

  • Form Events in Acrobat 9 Standard

    I'm trying to programatically have my form fields highlighted when opened by a user in Reader.  I've seen some other posts recommending setting the app.runtimehighlight event to true but I can't find the form events.  Any help would be appreciated.

  • Nokia Lumia 620 incoming call slide up isssue

    Hi All, Many a times Its found that when I receive a call, the "Slide up" option on the screen does not work. There is no scratch guard on the screen and the screen is perfectly clean. Does any one face same kind of issue. Thanks.

  • Viewing photos from PC.

    i have over 10000 photos on my pc. i want to use the slideshow feature to randomly display my photos on my apple tv. it seems to only rotate through about 100 or so. how can i get apple tv to display ALL my photos. this is the main reason i bought an

  • How Server can read client side SSL certificates through java code?

    My code will be running on server which will be a java class that should read any SSL certificates for the user that is logging in to the application. Kindly let me know how it can be achieved ? I have very rare knowldge on Security. how i can read S

  • Swapping to a business skype account for myself

    Hi I have been using skype for 4 years now and love it. I have a business team of 6 collegues and I am thinking to sign up to the business manager option for us all. My own personal skype account is what I have always used therefore its for personal