RTF/txt file printing.

Heya!
It's been doing my head in trying to figure out how to print JasperReport labels on my Dymo LabelWriter. What i used to do is to export the report to PDF and print it. Issue i had with that is that it ignores font type/family completely. What i noticed is that RTF and txt-files keep the font.
That threw me out on a journey to figure out how to print those. I've been through countless posts on the web, examples, forum posts, etc. All of them show some weird, useless to me scenarios that i couldn't even modify for my own use.
What I'm really looking for is this:
- A way to print .docx, .doc, .rtf or .txt file (physical file on a harddrive) to printer through Java code.
Is it possible? Perhaps some free libs i didnt notice yet?
Thanks in advance!

Now this is "internets" and there is no way to tell the tone, but it just seemed that he went on "for hours" about how dumb i am and how i ignored the content of his post (which i didnt, it just wasnt 100% relevant), while one sentance was enough. Anyway....
I did get it to print the .txt with BufferedReader (printing RTF was a failure, since it printed all the metadata with it, no surprise there).
File txtFile = new File("label.txt");
JRTextExporter txtExporter = new JRTextExporter();
txtExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
txtExporter.setParameter(JRExporterParameter.OUTPUT_FILE, txtFile);
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Float(6.55));//6.55 //6
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Float(11.9)); //11//10
txtExporter.exportReport();
There is also a JRPdfExporter and JRrtfExporter. PDF worked like a charm, except that it completely ignored the font i set in iReport (when i created the report structure).
I use BufferedReader with JTextArea to print the contents of my .txt file for now (txtArea.print() ), and it works fine, just needs adjustments on the numbers in the code above. However, i need to nudge the frame a bit in the right direction. At the moment there is like a good 5 cm top and left whitespace to the label itself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • With webutil-client_host, send txt file to client printer

    hi,
    I wanna to learn how to send a txt file to client default printer(local or network),
    I created txt file at client disk, and try to send printer directly,
    just try some statement looks like below;
    a.client_host('cmd /c start print C:\TEMP399899.txt /d:lpt1');
    b.client_host('cmd /c start copy C:\TEMP399899.txt lpt1');
    I do not know the command prompt syntax, please help me, reference me,
    thanks

    Hi,
    on a command line type
    print /?
    for the help of how to print documents. On XP this help is
    PRINT [D:device] [[drive:][path]filename[...]]
    /D:device Specifies a print device.
    Frank

  • Problem with printing txt file

    I have a problem with printing txt file. My code looks like :
    String filename = something.txt";
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintService[] services = PrintServiceLookup.lookupPrintServices(
              flavor, null);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    pras.add(PrintQuality.DRAFT);
    pras.add(new Copies(1));
    pras.add(MediaSizeName.ISO_A4);
    pras.add(Sides.ONE_SIDED);
    pras.add(Chromaticity.MONOCHROME);
    PrintService service = ServiceUI.printDialog(null, 200, 200,
              services, services[0],
              null,
              pras);
    if (service != null)
    try
    DocPrintJob job = service.createPrintJob();
    FileInputStream fis = new FileInputStream(filename);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc = new SimpleDoc(fis, flavor, das);
    job.print(doc, pras);
    Thread.sleep(10000);
    catch(FileNotFoundException e)
    catch(PrintException e1)
    catch(InterruptedException e2)
    It doesn't work :(
    What is my purpose: I would like to print .txt file but I would like to get PrintDialog where I can choose PrintQuality, Chromaticity etc. I found also that I should use DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST but I don't know how.
    I will be very gratefull for help :)

    I tested it on 3 printers (different models of hp). 2 of them don't give me any error but when it started print priter stoped (just as it dosesn't have a paper), but 1 of them doesn't react (there were no errors), i thought tahat something was wrong with printers but when I change DocFlavor.INPUT_STREAM.AUTOSENSE to DocFlavor.GIF and filename to dog.gif it works so mybe there is another way to print txt file

  • How do I save a file as an unformatted txt file instead of html or rtf?

    How do I save a file as an unformatted txt file instead of html or rtf?

    Use menu Image>Image Size in the image size dialog uncheck Resample and enter 300 in the resolution field and click OK.  Note no Pixels are changed only the resolution setting get changed.  The use Menu Fils>Save As in the save as dialog use the file type pull down and select Tiff then click Save
    In the Tiff Option Dialog in the Image Compression  section set None The click OK.

  • Print from .csv or .txt file

    Hello Experts,
    I am new to ABAP development.
    Is there any way to print the content of an .csv or .txt file.
    For example my report will have a selection screen where we will upload a file containing "Hello world" when we execute the output screen will show "Hello World".
    Regards,
    Sarnava

    Hi Sarnava,
    If your are selecting file from your system desktop then use  GUI_UPLOAD to upload data in data_tab and then while applying loop at this internal table split the code at ',' or space and fill internal table with your relevant fields.
    Loop at final internal table and display on output screen.
    DATA: BEGIN OF I_APPFEED OCCURS 0,
             RECORD(200)  TYPE C,
           END   OF I_APPFEED.
    CALL FUNCTION 'GUI_UPLOAD'
         EXPORTING
           FILENAME                = LV_FILE (path of .csv file from desktop)
         TABLES
           DATA_TAB                = I_APPFEED
    LOOP AT I_APPFEED INTO GWA_LOC_APP.
         SPLIT GWA_LOC_APP AT ','
        into wa_fields.
    append wa_fields to it_fields.
    endloop.
    loop at it_fields into wa_fields
    write: wa_fields-fields.
    endloop.
    Hope, this will solve your issue or let me know if you want something else.

  • How do Print TXT file in JAVA...?

    Dear sir,
    i have a program for printing txt file.... i tried below program..
    1. This code executed without exception... but its not printing.... when i saw print buffer, file is add but not printing
    2. Please help me out.... or give me some clue.... where i doing wrong....?
    Note:- am trying remote printing
              try {
                   FileInputStream fin = new FileInputStream(".\\file\\down.txt");
                   // set up attributes set
                   PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                   pras.add(new Copies(1)); // number of copies
                   // find the priner service
                   PrintService pss = PrintServiceLookup.lookupDefaultPrintService();
                   if (pss == null)
                        throw new RuntimeException("No printer services available.");
                   PrintService ps = pss;
                   System.out.println("Printing to " + ps);
                   // create print job
                   DocPrintJob job = ps.createPrintJob();
                   // print data
                   Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                   // print it
                   job.print(doc, pras);
                   // close file
                   fin.close();
              } catch (IOException ie) {
                   ie.printStackTrace();
              } catch (PrintException pe) {
                   pe.printStackTrace();
              }Thank you
    boss134

    Hi ,
    i m asking if you got a solution for your problem ;
    i need solution to the same problem
    thx in advance

  • Print Workbench generating txt file

    Hello,
    we are using Print Workbench to generate bill forms. We will send a file to the Print Center.
    The problem is that our form (SmartForm) generates a XML file, and the Print Center expects to receive a TXT file.
    Does anybody know how to generate the TXT file directly?
    We don't want to generate XML and then convert to TXT...
    Cheers
    Adriano

    Use printer defined with device type ASCIIPRI when printing and set 'Standard format' as output format in the smartform general attributes.
    Regards
    Sridhar

  • Saving .txt files as .rtf's

    I have a bunch of .txt files that were created in Windows. When I open them in OS X, they appear in TextEdit, and the font is Monaco. Pretty unattractive. So I Command-A to select all, then go to Show Fonts, and change the whole document to Arial. I save it, but the Save window doesn't give me the option to save it as Rich Text. The choices are all Plain Text encodings. So even though I'm saving the document with Arial, the next time I open it, it's back to Monaco.
    My workaround has been to just copy the text, paste it into a new TextEdit document, and there I am able to save it as an .rtf.
    My question is: is there a faster, easier way to change the font in these Windows-created .txt files and then save them as .rtfs?
    Thanks in advance ...

    Plain text files contain text only -- no formatting information at all, including font selection. If you don't like Monaco, then change the Plain Text font in TextEdit Preferences.

  • Printing TXT files with java

    Hi !!
    I�m trying to send the content of a .txt file to the default printer whith the next code; I read the file, and this method accept a String with the content I must print.
    // I�ve read the code in this forum, and I only made little changes....
    public void PrintFileString(String fileContent){
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    // getting PrintService
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
    if (service != null){
    System.out.println("Default Printer: " + service.getName());
    // Creating DocPrintJob
    DocPrintJob job = service.createPrintJob();
    try{
    // String to InputStream
    ByteArrayInputStream bais = new ByteArrayInputStream(fichero.getBytes());
    Doc doc = new SimpleDoc(bais,flavor,null);
    job.print(doc,aset);
    catch(Exception a){
    System.out.println(a + "error");
    I can print, in the default printer, but I need to change properties of printed document, like orientation, margins, number of copies, etc....
    Can I do it ??
    Really Thanks

    Please, help !!!
    I need to print a file in landscape mode.
    My code is:
    public class BasicPrint {
        public static void main(String[] args) {
            try {
                // Open the  file
                InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\diego.txt"));
                // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
                PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                // put landscape mode
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.LANDSCAPE);
                // Create the print job
                DocPrintJob job = service.createPrintJob();
                Doc doc = new SimpleDoc(is, flavor, null);
                try {
              job.print(doc, aset);
             } catch (PrintException e1) {
              e1.printStackTrace();
                // It is now safe to close the input stream
                is.close();
            } catch (IOException e) {
    }The text always is printed in the default orientation (portrait)
    I�ve tried with an image file (gif) changing the lines
      // Open the  file
      InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\diego.txt"));
      // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;by
      // Open the  file
      InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\image.gif"));
      // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;and works fine !!!
    but not with text. Why ???
    The line
    aset.add(new Copies(2));
    to print 2 copies, don�t work.
    Please, some help ???

  • Send a txt file to the printer with java

    Hello,
    I want to sent a txt file to the printer in java. I' am using the USB port. I can try to setup a dos command (print c:\test.txt), but I don't know the exactly command.
    There is also another solution in java I thing but I don't know the code!
    Can somebody give me the exact command for DOS and/or the code I have to write in java?
    THANX!!!!

    in dos imo you are not able to use usb-port. if your printer would be on lpt you could use javacomm ( http://java.sun.com/products/javacomm/index.html ). there is also another thread talking about this (print text to lpt). for your usb-problem i don't have a solution. but you could use JNI (java native interface). write code in c, compile to dll and use it in java.
    tobias
    ps: the other thread ( http://forum.java.sun.com/thread.jsp?forum=31&thread=224460 )

  • Automatic Print of output .txt file - Visual Studio Basic 2013

    Hi all,
    I am wondering if someone knows the code for printing a .txt file automatically.
    Thanks in advance for any help.
    Konstantina.

    Here is one way: from
    http://msdn.microsoft.com/en-us/library/cwbe712d.aspx
    Imports System
    Imports System.Drawing
    Imports System.IO
    Imports System.Drawing.Printing
    Imports System.Windows.Forms
    Public Class Form1
    Inherits Form
    Private printButton As Button
    Private printDocument1 As New PrintDocument()
    Private stringToPrint As String
    Public Sub New()
    Me.printButton = New System.Windows.Forms.Button()
    Me.printButton.Location = New System.Drawing.Point(12, 51)
    Me.printButton.Size = New System.Drawing.Size(75, 23)
    Me.printButton.Text = "Print"
    Me.ClientSize = New System.Drawing.Size(292, 266)
    End Sub
    Private Sub ReadFile()
    Dim docName As String = "testPage.txt"
    Dim docPath As String = "c:\"
    printDocument1.DocumentName = docName
    Dim stream As New FileStream(docPath + docName, FileMode.Open)
    Try
    Dim reader As New StreamReader(stream)
    Try
    stringToPrint = reader.ReadToEnd()
    Finally
    reader.Dispose()
    End Try
    Finally
    stream.Dispose()
    End Try
    End Sub
    Private Sub printDocument1_PrintPage(ByVal sender As Object, _
    ByVal e As PrintPageEventArgs)
    Dim charactersOnPage As Integer = 0
    Dim linesPerPage As Integer = 0
    ' Sets the value of charactersOnPage to the number of characters
    ' of stringToPrint that will fit within the bounds of the page.
    e.Graphics.MeasureString(stringToPrint, Me.Font, e.MarginBounds.Size, _
    StringFormat.GenericTypographic, charactersOnPage, linesPerPage)
    ' Draws the string within the bounds of the page
    e.Graphics.DrawString(stringToPrint, Me.Font, Brushes.Black, _
    e.MarginBounds, StringFormat.GenericTypographic)
    ' Remove the portion of the string that has been printed.
    stringToPrint = stringToPrint.Substring(charactersOnPage)
    ' Check to see if more pages are to be printed.
    e.HasMorePages = stringToPrint.Length > 0
    End Sub
    Private Sub printButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    ReadFile()
    printDocument1.Print()
    End Sub
    <STAThread()> _
    Shared Sub Main()
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
    Application.Run(New Form1())
    End Sub
    End Class

  • Editing and printing to the beginning of a txt file

    I have to questions that I have not been able to find much on. I have an output file but instead of the new data going on bottom I would like it to go on top. I'm sure there is a method or something but I have not been able to find it. Any help would be appreciated. And I would also like this txt file to be able to be edited throught the web page I'm using so in case something changes I don't have to go in and manual do the changes on the server. Thanks in advance for the help.

    alright I figured out how to put the values in at the top but I still would like a way to edit it in a browser. I was thinking of putting the entire text file back into a text area and when the submit button is hit it rewrites the entire file. Anyone done this before or got any better ideas. Thanxs.

  • Problem on reading and writing from from a *.txt file

    I get Problem on reading and writing from from a *.txt file. The following is the read() method...
    The software said the DataInputStream is depreciated. Can anyone help me please?
    public void read()
        File file = new File("C://Documents and Settings//Charles//My Documents//Brunel//EE2065//Assignment and Lab//Assignment 4 and Lab 4//data.txt");
        FileInputStream in = null;
        String str = "";
        try
          in = new BufferedReader(file);
          //in = new FileInputStream(file);
          for(;;)
            str = new BufferedReader(in).readLine();
            //str = new DataInputStream(in).readLine();
            if(str == null)
              break;
            System.out.print(str);
        in.close();
        catch(IOException e)
            System.err.println("execution error: " +e);
      }

    Thank you for your reply. I have made some change. However, there is an incompetable type found error.
    in = new BufferedReader(new InputStreamReader(in));The following are all of the code.
    public void read()
        File file = new File("C://Documents and Settings//Charles//My Documents//Brunel//EE2065//Assignment and Lab//Assignment 4 and Lab 4//data.txt");
        FileInputStream in = null;
        //BufferedReader in = null;
        String str = "";
        try
          in = new BufferedReader(new InputStreamReader(in));
          //in = new FileInputStream(file);
          for(;;)
            BufferedReader Bstr = new BufferedReader(new InputStreamReader(in));
            //str = new BufferedReader(in).readLine();
            //str = new DataInputStream(in).readLine();
            if(str == null)
              break;
            System.out.print(str);
        in.close();
        catch(IOException e)
            System.err.println("execution error: " +e);

  • Create txt file at runtime

    I'm working on a biological database. People see the data via jsp pages. Now at runtime a very long string is created depending on the needs of the user. This data is derived from different tables and the output string can be up to 5000 characters. Now this output can be used by the user as input for several biological research applications. Now I can create this string at runtime and can print it in a jsp page. But it would be easier for the users if this string would be written at runtime to a txt file(or an extension supported by these applications). So that users only have to press a button, there will be a txt file created and opened in a different browser window (or maybe better would be a dialog box with the choice to save to disk or to open), so that people can easily save it and later on import this file in their applications rather than have to copy the string from a jsp page and paste it in a text editor. How can I do this???
    Thanx,
    Lieven

    Ok I did some research by myself and discovered to set the contenType to application/octet-stream. The problem is now that the extension of the output file is still jsp. So how can I change this to the filename and extension of my choice???
    thanx,
    Lieven

  • Strange Charz shown in my created .TXT file

    Hi,
    I have createt an empty .txt file with the following command:
    FileOutputStream fot = new FileOutputStream("Test.txt");
    Then I wrote a simple String into it which should be written into 2 lines like that:
    MY FIRST
    TEXTFILE
    I used that code snippet:
    String x = new String("MY FIRST\nTEXTFILE");
    DataOutputStream dos = new DataOutputStream (fot);
    dos.writeUTF(x);
    But instead of my wanted result i got something like this:
    MY FIRSTTEXTFILE
    if i show this with NOTEPAD.
    The result in Word2000 looks like this:
    MY FIRST
    TEXTFILE
    I hope somebody can tell my how I have to write it to a file that it looks like this:
    MY FIRST
    TEXTFILE
    without the ugly "".
    THNX in advance
    BraiNbuG

    The 'System.getProperty("line.separator")' was pretty good. But I have already the prolem with de Charz on the beginning. But now they are not anymore such squares. They are simple Charz like ' a' & ' f' & ...
    I show you a snippet of my log fil, which i want to create out of a program:
    fTue Dec 18 11:41:24 GMT+01:00 2001 [JDBCAdapter.JDBCAdapter]
    Try to open Database connection ....
    �Tue Dec 18 11:41:30 GMT+01:00 2001 [DataManager.jM_stamm_kunden_neuActionPerformed]
    Leeres Formular fuer neuen Kundeneintrag oeffnen
    aTue Dec 18 11:41:35 GMT+01:00 2001 [DataManager.jM_sys_endeActionPerformed]
    Auf Wiedersehen!
    Each row which contains the Date has such a Char at the beginning which isn't present in the String.
    Here is the CLASS I've written to output such a log-File:
    public class SystemMessage
    boolean SCREEN_OUTPUT = true;
    boolean FILE_OUTPUT = true;
    Date datum;
    FileOutputStream f;
    String VisualString = new String("");
    public SystemMessage()
    try
    f = new FileOutputStream(".\\DataManager.log",true);
    catch(IOException ioe)
    System.err.println(ioe);
    public void print(String Message, String className)
    datum = new Date();
    VisualString = datum.toString() +
    " ["+className+"]" +
    System.getProperty("line.separator") +
    " " + Message +
    System.getProperty("line.separator");
    if(SCREEN_OUTPUT)
    System.out.println(VisualString);
    if(FILE_OUTPUT)
    try
    DataOutputStream dos = new DataOutputStream (f);
    dos.writeUTF(VisualString);
    catch (IOException e)
    System.err.println(e);
    Myabe you can find a error which I've made
    Again THNX in advance,
    BraiNbuG

Maybe you are looking for

  • Formatting Issues when saving\viewing in PDF

    I sure hope I am in the right place.... I am using Adobe to print documents as PDF files for printing\saving. Why does Adobe push information down to the next page leaving  an extensive blank area? The information continues on the next page but it is

  • Using factory calendars in BI transformations

    Hello All, Do we have the option of using factory calendars in BI transformations, like we had in 3.x version update rules. I did not see any option for choosing the factory calendar, so i guess we will have to use function modules. Please let me kno

  • Material Document change

    Dear All, Can material document be changed once it's been created? User wants to update Delivery Note in Matetial document, is there any transaction to do that? Regards SD

  • IOS 4.1 & Alpine Car Audio

    Hello, I have an Alpine CDE-113BT and yesterday I upgraded the iPhone to the 4.1, since I done it the car-audio doesn't recognize the iPhone and shows me this message 'Error 01'. Alpine refered to Apple to solve this issue. Thanks You

  • Adobe air crashing league or legends 2 months now no play plz help!

    for about 2 months I havent been able to play LOL because right after champion select it boots me to the desktop with a adobe air debugger has stopped working error message. I have put in MANY tickets to Riot with NO RESPONSE... nothing ..... my husb