stoe288
Goto Top

XDocument

Hallo administrator- und Java-Gemeinde,

für eine aktuelles Projekt möchte ich mit einem Java Programm PDF Dokumente erstellen, welche auf vorhanden Dokumententemplates von OpenOffice 2.3.1 Writer/ Calc (alternativ MS Word/ MS Excel) basieren.

Ein gutes Ausgangsscript habe ich schon unter http://www.oooforum.org/forum/viewtopic.phtml?t=61386 gefunden.
Da ich allerdings schon seit 2 Jahren keine Java mehr programmiert habe, komm ich bei der
public void saveDoc( 
            XDocument document, 
            String saveFile, 
            DocumentFormatEnum format, 
            boolean overwrite) throws java.lang.Exception { 

        if ((saveFile == null) || (saveFile.trim().length() == 0)) { return; } 
        if (! overwrite) { 
            File f = new File(saveFile); 
            if (f.exists()) { 
                throw new java.lang.Exception( 
                        "File " + saveFile + " already exists; overwriting disabled.");   
            } 
        } 

        String saveFileURL = filePathToURL(saveFile); 
        XStorable storable = (XStorable) UnoRuntime.queryInterface( 
                XStorable.class, document); 

        PropertyValue properties = new PropertyValue[1]; 
        PropertyValue p = new PropertyValue(); 
        p.Name = "FilterName";   
        p.Value = format.getFormatCode(); 
        properties = p; 

        storable.storeAsURL(saveFileURL, properties); 
    }
nicht weiter.

Vielleicht kann mir hier jemand einen Tipp geben, wie ich
saveDoc( 
            XDocument document, 
            String saveFile, 
            DocumentFormatEnum format, 
            boolean overwrite) throws java.lang.Exception
in meinem Aufruf definieren muss, dammit das PDF gespeichert wird.

public static void main(String args) {
		String templateDoc =
            "C:/pfad/zur/vorlage.odt";  
		String savePath =
            "C:/pfad/zur/datei.pdf";  

        WriterDoc doc = new WriterDoc();
        DocumentFormatEnum pdf = DocumentFormatEnum.PDF;
        try {
        	XDocument handle =  (XDocument) doc.createDoc("My Document Title", templateDoc, true);  
        	doc.saveDoc(handle, savePath, pdf, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
	}
hat leider nicht funktioniert ... er erstellt mir zwar das Dokument anhand des Templates, aber das PDF wird nicht generiert.

Für Eure Hilfe bedanke ich mich bereits im Voraus.

Viele Grüße
stö

Content-Key: 76015

Url: https://administrator.de/contentid/76015

Printed on: April 23, 2024 at 20:04 o'clock