0

i have been searching the whole day for a solution but i'm unable to find one. That's why i decided to ask a question.

My problem is that i'm inserting a ellipse object to the PPTX file. When i tries to open the presentation MS OFfice says it's corrupted and tries to repair. It ends up deleting the slide and presents the master slide.

See below my code:
the function officeXReport.getTemplatename() contains the filename of the PPTX (e.g. *Status_Report_template.pptx*)
The template pptx file contains only 1 slide.
The function officeXReport.getNewfilename() contains the new filename of the PPTX (e.g. *Status_Report_2014-03-16.pptx*)

try {
    PresentationMLPackage presentationMLPackage = (PresentationMLPackage)OpcPackage.load(new java.io.File(officeXReport.getTemplatename()));
    MainPresentationPart pp = presentationMLPackage.getMainPresentationPart();                  
    boolean noLine = false;                
    STShapeType st = STShapeType.ELLIPSE;
    int i = 1; 

    SlidePart slidePart = (SlidePart)presentationMLPackage.getParts().getParts().get(pp.getSlide(0).getPartName());

    Shape sample = ((Shape)XmlUtils.unmarshalString(
                    getPresetShape(st.value(), noLine, Long.toString(1839580), Long.toString(1314971), Long.toString(184337), Long.toString(184338), "92D050"), Context.jcPML) );
    slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);

    presentationMLPackage.save(new java.io.File(officeXReport.getNewfilename()));
} catch (Exception ex) {
    System.out.println("Exception thrown = " + ex.getMessage());
    return null;
}

The related function getPresetShape():

private static String getPresetShape(String preset, boolean noLine, String x, String y, String cx, String cy, String colorcode) {
String txBody = "";
String ln = "";
String style = "";

if (!noLine) {
    ln = "<a:ln w=\"3175\">"
            +"<a:solidFill>"
            +"<a:srgbClr val=\"000000\"/>"
            +"</a:solidFill>"
        +"</a:ln>";

    style = "<p:style>\n" +
        "<a:lnRef idx=\"1\">\n" +
        "<a:schemeClr val=\"accent1\"/>\n" +
        "</a:lnRef>\n" +
        "<a:fillRef idx=\"3\">\n" +
        "<a:schemeClr val=\"accent1\"/>\n" +
        "</a:fillRef>\n" +
        "<a:effectRef idx=\"2\">\n" +
        "<a:schemeClr val=\"accent1\"/>\n" +
        "</a:effectRef>\n" +
        "<a:fontRef idx=\"minor\">\n" +
        "<a:schemeClr val=\"lt1\"/>\n" +
        "</a:fontRef>\n" +
        "</p:style>";

    txBody = "<p:txBody>\n" +
        "<a:bodyPr rtlCol=\"false\" anchor=\"ctr\"/>\n" +
        "<a:lstStyle/>\n" +
        "<a:p>\n" +
        "<a:pPr algn=\"ctr\"/>\n" +
        "<a:endParaRPr lang=\"en-US\" sz=\"1100\" u=\"sng\" dirty=\"false\">\n" +
        "<a:latin typeface=\"Futura Com Light\" panose=\"020B0402020204020303\" pitchFamily=\"34\" charset=\"0\"/>\n" +
        "</a:endParaRPr>\n" +
        "</a:p>\n" +
        "</p:txBody>";
}

return 
       "<p:sp   xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">"
           + "<p:nvSpPr>"
                   + "<p:cNvPr id=\"32\" name=\"Ellipse 2\" />"
                   + "<p:cNvSpPr/>" 

                   + "<p:nvPr/>"

           + "</p:nvSpPr>"
           + "<p:spPr>"
                   + "<a:xfrm>"
                           + "<a:off x=\"" + x + "\" y=\"" + y + "\"/>"
                           + "<a:ext cx=\"" + cx + "\" cy=\""+ cy + "\"/>"
                   + "</a:xfrm>"
                   + "<a:prstGeom prst=\"" + preset + "\">"
                   + "<a:avLst/>"
                   + "</a:prstGeom>"
                   + "<a:solidFill>"
                       + "<a:srgbClr val=\""+ colorcode + "\"/>"
                   + "</a:solidFill>"
                   + ln
           + "</p:spPr>"
           + style
           + txBody
        + "</p:sp>";
}

I have looked into the slide1.xml file which is missing the XML header compared to a correct slide1.xml file :

<?xml version="1.0" encoding="UTF-8" standalone="true"?>

How can i get the xml header definition into the slide1.xml ?

Thanks,

Asad

CSchulz
  • 10,882
  • 11
  • 60
  • 114
Asad Khan
  • 61
  • 6
  • Can you put somewhere a pptx containing a slide with the object you are trying to recreate? – JasonPlutext Mar 06 '14 at 19:21
  • Please find the pptx file here : [link](http://www.asadkhan.de/Status_Report_Template.pptx) – Asad Khan Mar 06 '14 at 20:19
  • I'm trying to put the ellipse objects for Status, Scope, Budget, Quality, Resources and Timeline. Somehow creating the objects the pptx gets corrupted. – Asad Khan Mar 06 '14 at 20:21
  • "The Website Ahead Contains Malware! Google Chrome has blocked access to www.asadkhan.de for now. Even if you have visited this website safely in the past, visiting it now is very likely to infect your computer with malware." – JasonPlutext Mar 06 '14 at 22:05
  • You can continue ... it's a 60KB powerpoint. It's my private web server. Don't worry. It's safer than other fileshare services on the internet. – Asad Khan Mar 06 '14 at 22:44
  • 1
    "Don't worry. It's safer than other fileshare services on the internet". Um, doesn't sound like it to me... – Ben Mar 11 '14 at 08:58

0 Answers0