Hallo, nach einiger Suche hab ich bisher nichts gefunden.
Ich habe folgende Klasse, welche ein PDF in ein PPT umwandeln soll:
Diese hat mal funktioniert, tut es mittlerweile nicht mehr. Es kommt folgender Fehler:
(Jacob 1.7 wird benutzt)
Da das Jacob-Projekt schon länger nicht mehr unterstützt wird, hätte ich gerne eine aktuelle Alternative, wo das ganze ähnlich schnell abgehandelt werden kann.
SWT scheint mir sehr auf Graphik ausgelegt zu sein, JNI ist ein Interface, ich muss also noch viel selbst implementieren?
JNA sieht mir am ehesten danach aus, als könnte es mir weiterhelfen, liege ich da richtig? Wenn ja gibt es irgendwo ein gutes Tutorial?
lg und Danke schonmal fürs Textwall-lesen.
Ich habe folgende Klasse, welche ein PDF in ein PPT umwandeln soll:
Java:
import com.jacob.com.*;
import com.jacob.activeX.*;
public class Pdf2Ppt extends Thread {
static final int xConst = 839;
static final int yConst = 594;
static final int zoomFactor = 100;
int x;
int y;
String pdfFileName = "";
String pptFileName = "";
boolean onlyFirstPage = true;
public static void main(String[] args) {
execute(".\1.pdf", ".\1.ppt", true);
}
public Pdf2Ppt(String pdfFileName, String pptFileName, boolean onlyFirstPage) {
this.pdfFileName = pdfFileName;
this.pptFileName = pptFileName;
this.onlyFirstPage = onlyFirstPage;
this.x = xConst;
this.y = yConst;
}
public Pdf2Ppt(String pdfFileName, String pptFileName, boolean onlyFirstPage, int xUser, int yUser) {
this.pdfFileName = pdfFileName;
this.pptFileName = pptFileName;
this.onlyFirstPage = onlyFirstPage;
this.x = xUser;
this.y = yUser;
}
public static synchronized void execute(String pdfFileName, String pptFileName, boolean onlyFirstPage) {
// generate thread
Pdf2Ppt aPdf2Ppt = new Pdf2Ppt(pdfFileName, pptFileName, onlyFirstPage);
// change the priority (5 = normal)
try {
aPdf2Ppt.setPriority(5);
} catch (Exception e) {
e.printStackTrace();
}
// start thread
aPdf2Ppt.start();
// wait for termination
try {
aPdf2Ppt.join();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return;
}
public static synchronized void execute(String pdfFileName, String pptFileName, boolean onlyFirstPage, int xUser, int yUser) {
// generate thread
Pdf2Ppt aPdf2Ppt = new Pdf2Ppt(pdfFileName, pptFileName, onlyFirstPage, xUser, yUser);
// change the priority (5 = normal)
try {
aPdf2Ppt.setPriority(5);
} catch (Exception e) {
e.printStackTrace();
}
// start thread
aPdf2Ppt.start();
// wait for termination
try {
aPdf2Ppt.join();
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return;
}
public synchronized void run() {
// **********************
// ******** pdf *********
// **********************
ComThread.InitSTA();
// *** PDDoc ***
// Set pddoc = avdoc.GetPDDoc
ActiveXComponent pddoc = new ActiveXComponent("AcroExch.PDDoc");
//Dispatch pddoc = Dispatch.call(pdf, "pddoc").toDispatch(); //(Dispatch) new ActiveXComponent("AcroExch.PDDoc");
ActiveXComponent.call(pddoc, "Open", new Variant(pdfFileName));
// Set rect = CreateObject("AcroExch.Rect")
ActiveXComponent rect = new ActiveXComponent("AcroExch.Rect");
// Set point = CreateObject("AcroExch.Point")
//Dispatch point = (Dispatch) new ActiveXComponent("AcroExch.Point");
// get number of Pages
int pdfNumPages = 1;
if (onlyFirstPage == false) {
pdfNumPages = Integer.parseInt(Dispatch.call(pddoc, "GetNumPages") + "");
}
// Initialisze the ppt main objects
ActiveXComponent pptApp = null;
ActiveXComponent pptPres = null;
// Iterate over all pages of the pdf
for (int i = 0; i < pdfNumPages; i++) {
// *** CopyToClipboard ***
// Set pdpage = pddoc.AcquirePage(PageNumber)
Dispatch pdpage = Dispatch.call(pddoc, "AcquirePage", new Variant(i)).toDispatch();
// System.out.println("Current page [index]: " + Dispatch.call(pdpage, "GetNumber"));
// Set point = pdpage.GetSize
//point = Dispatch.call(pdpage, "GetSize").toDispatch();
//int x = (Dispatch.get(point, "X")).toInt();
//int y = (Dispatch.get(point, "Y")).toInt();
// System.out.println("X: " + x + ", Y: " + y);
//int zoomFactor = 173;
// rect.Top = RectTop
rect.setProperty("Top", new Variant(0));
// System.out.print("Top: " + Dispatch.call(rect, "Top"));
// rect.Left = RectLeft
rect.setProperty("Left", new Variant(0));
// System.out.print(", Left: " + Dispatch.call(rect, "Left"));
// rect.Right = point.X * (zoomFactor / 100)
rect.setProperty("Right", new Variant(x * (zoomFactor / 100.0)));
// System.out.print(", Right: " + Dispatch.call(rect, "Right"));
// rect.Bottom = point.y * (zoomFactor / 100)
rect.setProperty("Bottom", new Variant(y * (zoomFactor / 100.0)));
// System.out.println(", Bottom: " + Dispatch.call(rect, "Bottom"));
// Boolean b = pdpage.CropPage(rect)
ActiveXComponent.call(pdpage, "CropPage", rect);
//Boolean X = pdpage.CopyToClipboard(rect, 0, 0, zoomFactor)
ActiveXComponent.call(pdpage, "CopyToClipboard", rect, new Variant(0), new Variant(0), new Variant(zoomFactor));
// **********************
// ******** ppt *********
// **********************
// *** initialize PPT objects ***
if (i == 0) {
// Set PPTApp = CreateObject("PowerPoint.Application")
pptApp = new ActiveXComponent("PowerPoint.Application");
//DEBUG: pptApp.setProperty("Visible", new Variant(true));
// Set PPTPres = PPTApp.Presentations.Add
ActiveXComponent presentations = (ActiveXComponent) pptApp.getProperty("Presentations").toDispatch(); //Dispatch.call(pptApp, "Presentations").toDispatch();
pptPres = (ActiveXComponent)ActiveXComponent.call(presentations, "Add").toDispatch();
// PPTPres.PageSetup.SlideHeight = 594
ActiveXComponent pageSetup = (ActiveXComponent)ActiveXComponent.get(pptPres, "PageSetup").toDispatch();
ActiveXComponent.put(pageSetup, "SlideHeight", new Variant(y));
// PPTPres.PageSetup.SlideWidth = 839
ActiveXComponent.put(pageSetup, "SlideWidth", new Variant(x));
}
// *** adding slides to presentation ***
// Set PPTSlide = PPTPres.Slides.Add(i, ppLayoutBlank)
ActiveXComponent pptSlide = (ActiveXComponent)ActiveXComponent.call((Dispatch.get(pptPres, "Slides").toDispatch()), "Add", new Variant(1 + i), new Variant(12)).toDispatch();
// *** set background color ***
// PPTPres.SlideMaster.Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
ActiveXComponent slideMaster = (ActiveXComponent)ActiveXComponent.get(pptPres, "SlideMaster").toDispatch();
Dispatch background = Dispatch.get(slideMaster, "Background").toDispatch();
Dispatch fill = Dispatch.get(background, "Fill").toDispatch();
Dispatch foreColor = Dispatch.get(fill, "ForeColor").toDispatch();
Dispatch.put(foreColor, "RGB", new Variant(0xFFFFFF));
// *** iterating PDF document and insert as slide into presentation ***
// PPTPres.Slides.Item(i + 1).Shapes.Paste
Dispatch shapes = Dispatch.get(pptSlide, "Shapes").toDispatch();
Dispatch paste = Dispatch.call(shapes, "Paste").toDispatch();
// *** re-changing size ***
// With PPTPres.Slides.Item(i + 1).Shapes.Paste
// .Height = PPTPres.SlideMaster.Height
// .Width = PPTPres.SlideMaster.Width
// .Top = 0
// .Left = 0
Dispatch.put(paste, "Height", new Variant(y));
Dispatch.put(paste, "Width", new Variant(x));
Dispatch.put(paste, "Top", new Variant(0));
Dispatch.put(paste, "Left", new Variant(0));
// *** saving presentation and Exit ***
if (i == (pdfNumPages - 1)) {
// PPTPres.SaveAs PPTFile
Dispatch.call(pptPres, "SaveAs", new Variant(pptFileName));
Dispatch.call(pptPres, "Close");
Dispatch.call(pptApp, "Quit");
}
}
Dispatch.call(pddoc, "Close");
ComThread.Release();
}
}
Diese hat mal funktioniert, tut es mittlerweile nicht mehr. Es kommt folgender Fehler:
(Jacob 1.7 wird benutzt)
Exception in thread "Thread-0" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Presentations
Description: An unknown COM error has occured.
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java)
at Pdf2Ppt.run(Pdf2Ppt.java:153)
Da das Jacob-Projekt schon länger nicht mehr unterstützt wird, hätte ich gerne eine aktuelle Alternative, wo das ganze ähnlich schnell abgehandelt werden kann.
SWT scheint mir sehr auf Graphik ausgelegt zu sein, JNI ist ein Interface, ich muss also noch viel selbst implementieren?
JNA sieht mir am ehesten danach aus, als könnte es mir weiterhelfen, liege ich da richtig? Wenn ja gibt es irgendwo ein gutes Tutorial?
lg und Danke schonmal fürs Textwall-lesen.