java - Docx4j: PPTX got corrupted while inserting an ellipse object -
i have been searching whole day solution i'm unable find one. that's why decided ask question.
my problem i'm inserting ellipse object pptx file. when tries open presentation ms office says it's corrupted , tries repair. ends deleting slide , presents master slide.
see below code:
function officexreport.gettemplatename()
contains filename of pptx (e.g. *status_report_template.pptx*)
template pptx file contains 1 slide.
function officexreport.getnewfilename()
contains new filename of 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 = 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 slide1.xml file missing xml header compared correct slide1.xml file :
<?xml version="1.0" encoding="utf-8" standalone="true"?>
how can xml header definition slide1.xml ?
thanks,
asad
Comments
Post a Comment