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
nicht weiter.
Vielleicht kann mir hier jemand einen Tipp geben, wie ich
in meinem Aufruf definieren muss, dammit das PDF gespeichert wird.
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ö
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);
}
Vielleicht kann mir hier jemand einen Tipp geben, wie ich
saveDoc(
XDocument document,
String saveFile,
DocumentFormatEnum format,
boolean overwrite) throws java.lang.Exception
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();
}
}
Für Eure Hilfe bedanke ich mich bereits im Voraus.
Viele Grüße
stö
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 76015
Url: https://administrator.de/forum/xdocument-76015.html
Ausgedruckt am: 29.04.2025 um 06:04 Uhr