Datei schreiben (RTF oder PDF)



  • Hi Leute

    Bin schon wieder da 🙂

    diesesmal mit einer wirklich wichtigen frage
    Weiss irgendwer wie man aus einem Java Programm heraus ein RTF oder PDF File erzeugen kann (Notfalls tut es auch HTML)

    ich brauch das um mir das drucken zu ersparen und der user kann sich das ganze gleich in einem brauchbaren format abspeichern

    ich bin auch am ueberlegen ob ich nicht irgendwie einfach aus meinem XML dokument mit den Daten ein HTML Dokument erzeugen kann
    sollte ja mit XSL gehen (XPath und XSLT) => DAVON HAB ICH ABER KEINE AHNUNG

    danke im voraus

    gomberl



  • Leider kann ich dir nicht mehr sagen, als du eh schon weisst. Vielleicht noch ein Stichwort im Zusammenhang XML, XSLT ... XFO (XML Formatted Objects oder ähnlich) ... damit kann man dann tatsächlich PDF-Files generieren.



  • nur eine erste idee... ich habe mal mit pdf unter c rumgespielt ... hat klasse geklappt ... hier ein auszug aus dieser library..

    PDFlib V4.0.2

    Portable C library for dynamically generating PDF ("Adobe Acrobat") files,
    with support for many other programming languages.

    Copyright (c) 1997-2002 PDFlib GmbH and Thomas Merz. All rights reserved.
    PDFlib is a registered trademark of PDFlib GmbH.

    The PDFlib distribution is available from http://www.pdflib.com

    THIS IS NOT PUBLIC DOMAIN OR FREEWARE SOFTWARE --
    see end of this file for an overview of licensing and
    usage issues, and the file doc/PDFlib-license.pdf for details.

    The PDFlib purcharse order form for commercial usage can also
    be found in the doc directory.

    Overview

    PDFlib is a C library for generating PDF files. It offers a graphics
    API with support for drawing, text, fonts, images, and hypertext. Call PDFlib
    routines from within your client program and voila: dynamic PDF files!
    For detailed instructions on PDFlib programming and the associated API,
    see the PDFlib Programming Manual, included in PDF format in the
    PDFlib distribution.

    In addition, you can deal with existing PDF documents if you have
    the PDF import library (PDI). PDI is a separate product which is
    not available as open source.

    Supported Programming Environments

    The PDFlib core library can be built as a static library or a shared
    C library/DLL. PDFlib can be used from the following environments:

    - ANSI C libary (static or dynamic)
    - ANSI C++ via an object wrapper
    - Perl
    - Tcl
    - PHP hypertext processor
    - Python
    - RPG
    - Java via the JNI, including servlets
    - ActiveX/COM (Visual Basic, Active Server Pages with VBScript and JScript,
    Windows Script Host, Delphi, ColdFusion, and numerous other environments).
    The ActiveX edition of PDFlib is available separately.

    The necessary wrappers for attaching PDFlib to these environments are
    included in the distribution (except for ActiveX), as well as sample
    programs for all supported environments.

    http://www.pdflib.com/pdflib/

    da ist java dabei ... hab es mir grad durchgeschaut, vielleicht fahr ich gleich noch ne testfahrt.. hmm oder am wochenende 🙂



  • ok..
    testfahrt abgschlossen:)

    du musst einfach nur die jar in den classpath setzen .. und schon erstellst du wunderschöne pdf files...

    gibt es für java pur, jsp und servlets..

    hat sofort gefunzt 🙂

    hier ein beispiel :

    mport java.io.*;
    import com.pdflib.pdflib;
    
    public class hello
    {
        public static void main (String argv[]) throws
        OutOfMemoryError, IOException, IllegalArgumentException,
        IndexOutOfBoundsException, ClassCastException, ArithmeticException,
        RuntimeException, InternalError, UnknownError
        {
        int font;
        pdflib p;
    
        p = new pdflib();
    
        if (p.open_file("hello.pdf") == -1) {
            System.err.println("Couldn't open PDF file hello.pdf\n");
            System.exit(1);
        }
    
        p.set_info("Creator", "hello.java");
        p.set_info("Author", "Thomas Merz");
        p.set_info("Title", "Hello world (Java)");
    
        p.begin_page(595, 842);
    
        /* Change "host" encoding to "winansi" or whatever you need! */
        font = p.findfont("Helvetica-Bold", "host", 0);
    
        p.setfont(font, 18);
    
        p.set_text_pos(50, 700);
        p.show("Hello world!");
        p.continue_text("(says Java)");
        p.end_page();
    
        p.close();
        }
    }
    

    die funktionsübersicht ist dabei.. viel spaß 🙂



  • ach mist..

    ist aber keine freeware, wie da oben schon steht..

    die beispiele für java sind mit einem www... überdeckt..

    schaus dir trotzdem mal an.
    🙂

    ps: im notfall gehts auf jeden fall in php ... da ist es easy 😉
    pps: diese hier scheint frei zu sein http://www.lowagie.com/iText/
    die probier ich morgen mal ...

    [ Dieser Beitrag wurde am 18.07.2002 um 22:45 Uhr von elise editiert. ]



  • alles gut..

    die http://www.lowagie.com/iText/ sind ok..

    zieh dir die jar files von der sourceforge (die anderen links gehen nicht)
    die jars dann in den classpath.

    es gibt ein gutes onlinetutorial, mit einigen examples zum runterladen.

    auch hier die möglichkeit, durch servlets pdf zu generieren oder durch "normale" java anwendungen.
    zweiteres habe ich getestet und lief einwandfrei. für servlets muss ich gleich noch meine maschine anwerfen...

    so sähe hier eine testanwendung aus:

    import java.io.FileOutputStream;
    import java.io.IOException;
    
    import com.lowagie.text.*;
    import com.lowagie.text.pdf.PdfWriter;
    
    public class Chap0102 {
    
        public static void main(String[] args) {
    
            System.out.println("Chapter 1 example 2: PageSize");
    
            // step 1: creation of a document-object
            Rectangle pageSize = new Rectangle(144, 720);
            pageSize.setBackgroundColor(new java.awt.Color(0xFF, 0xFF, 0xDE));
            Document document = new Document(pageSize);
    
            try {
    
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
    
                PdfWriter.getInstance(document, new FileOutputStream("Chap0102.pdf"));
    
                // step 3: we open the document
                document.open();
    
                // step 4: we add some paragraphs to the document
                for (int i = 0; i < 5; i++) {
                    document.add(new Paragraph("hallo"));
                }
    
            }
            catch(DocumentException de) {
                System.err.println(de.getMessage());
            }
            catch(IOException ioe) {
                System.err.println(ioe.getMessage());
            }
    
            // step 5: we close the document
            document.close();
        }
    }
    

    also sehr übersichtlich.
    viel spaß 🙂



  • hi

    ich glaub das wird recht gut funktionieren
    muss jetzt mal runterladen und dann nen kleinen test machen
    aber das wird ja wohl nicht das problem sein, schaetze ich mal

    ich frag mich nur mal wieder wo der bloede classpath gesetzt wird
    es sollte reichen wenn ich es als filesystem mounte
    damit sollte sich der compiler zufrieden geben
    hoffe ich halt mal
    wenn nicht, dann nicht

    ich hasse das
    seitdem ich forte benutze weiss ich nie wo ich das alles umstellen kann, weil ich eigentlich nirgends meinen classpath direkt setze sondern das eine compiler option ist

    aber ich dank dir nochmal
    und werd mich am montag dahintersetzen

    lg

    gomberl



  • Hehe Klasse! So viel Einsatz gibts wohl in keinem Forum - wieder was für die FAQs 🙂


Anmelden zum Antworten