-
-
Save BenoitDuffez/b132d45747ef8c2e9e7c to your computer and use it in GitHub Desktop.
Apache POI issue when embedding images in header.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.bicou.upcab.ui.docs.export; | |
import net.bicou.upcab.model.docs.Document; | |
import net.bicou.upcab.model.docs.DocumentImage; | |
import net.bicou.upcab.model.docs.EditableTextLineStyle; | |
import net.bicou.upcab.model.docs.EditableTextSectionType; | |
import net.bicou.upcab.model.docs.EditableTextStyleRange; | |
import net.bicou.upcab.model.docs.TextFormatInfo; | |
import net.bicou.upcab.sqlite.DocumentsDbAdapter; | |
import net.bicou.upcab.ui.docs.DocumentCreator; | |
import net.bicou.upcab.util.L; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.custom.StyleRange; | |
import org.eclipse.swt.graphics.ImageData; | |
import org.eclipse.swt.graphics.Rectangle; | |
import org.eclipse.swt.widgets.Display; | |
import java.awt.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Scanner; | |
/** | |
* <b>Document creator</b> | |
* <p/> | |
* Merges a template with sqlite source instances, and creates the output file in a specific file format. | |
* <p/> | |
* Usage: | |
* <pre> | |
* // Prepare document ID and file path | |
* long documentId = 12; // example | |
* String filePath = "/path/to/file.pdf"; | |
* ExportFormat exportFormat = ExportFormat.PDF; | |
* | |
* // Export file | |
* Exporter exporter = Exporter.create(exportFormat); | |
* if (exporter == null) { | |
* // Unsupported file format | |
* } else { | |
* String errorMessage = exporter.export(documentId, filePath); | |
* if (errorMessage != null) { | |
* // Handle error | |
* } else { | |
* // Success! | |
* } | |
* } | |
* </pre> | |
* This class is independent of the implementation. API implementations should extend this class and register the implementation in {@link | |
* #create(net.bicou.upcab.ui.docs.export.Exporter.ExportFormat)} | |
* | |
* @author bicou | |
*/ | |
public abstract class Exporter { | |
static final Color sCellHeaderBackgroundColor = new Color(0xE6, 0xE6, 0xE6); | |
static final String CELL_HEADER_BACKGROUND_COLOR_RRGGBB = "E6E6E6"; | |
Document mDocument; | |
private final List<String> mErrors = new ArrayList<String>(); | |
EditableTextSectionType mCurrentSection; | |
int mImageIdInCurrentSection; | |
public enum ExportFormat { | |
DOCX, | |
PDF, | |
RTF, | |
} | |
public enum TextAlignment { | |
LEFT, | |
RIGHT, | |
CENTER, | |
JUSTIFY, | |
} | |
public enum ImageFormat { | |
PNG, | |
JPG, | |
} | |
/** | |
* Export the specific document to the desired file path | |
* | |
* @param docId The document ID | |
* @param filePath The target file path | |
* | |
* @return The error messages, if any | |
*/ | |
public List<String> export(final long docId, final String filePath) { | |
loadDocument(docId); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
// Create the document | |
createDocument(filePath); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
// Set document header | |
mCurrentSection = EditableTextSectionType.HEADER; | |
mImageIdInCurrentSection = 0; | |
startHeader(); | |
parseText(mDocument.header, mDocument.headerFormat); | |
endHeader(); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
// Set document footer | |
mCurrentSection = EditableTextSectionType.FOOTER; | |
mImageIdInCurrentSection = 0; | |
startFooter(); | |
parseText(mDocument.footer, mDocument.footerFormat); | |
endFooter(); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
// Open the document | |
mCurrentSection = EditableTextSectionType.BODY; | |
mImageIdInCurrentSection = 0; | |
openDocument(); | |
parseText(mDocument.body, mDocument.bodyFormat); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
// Close the document | |
closeDocument(); | |
if (mErrors.size() > 0) { | |
return mErrors; | |
} | |
return null; | |
} | |
@Override | |
public String toString() { | |
return "Exporter{" + | |
"mDocument=" + mDocument + | |
", mErrors=" + mErrors + | |
", mCurrentSection=" + mCurrentSection + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2014/05/15 00:45:15.261 [D] PoiExporter#createDocument(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:47) | |
2014/05/15 00:45:15.959 [D] PoiExporter#startHeader(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:54) | |
2014/05/15 00:45:15.960 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:408) | |
2014/05/15 00:45:15.960 [D] Exporter#parseText(): Text is: | |
 | |
Benoit Duffez (in net/bicou/upcab/ui/docs/export/Exporter.java:409) | |
2014/05/15 00:45:15.960 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:410) | |
2014/05/15 00:45:15.964 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.023 [D] PoiExporter#addImage(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:140) | |
2014/05/15 00:45:16.153 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.193 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.194 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.194 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.423 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.425 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.426 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.426 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.427 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.428 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.441 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.444 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.445 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.447 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.449 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.450 [D] PoiExporter#endHeader(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:59) | |
2014/05/15 00:45:16.556 [D] PoiExporter#startFooter(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:73) | |
2014/05/15 00:45:16.556 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:408) | |
2014/05/15 00:45:16.556 [D] Exporter#parseText(): Text is: | |
15/05/2014 (in net/bicou/upcab/ui/docs/export/Exporter.java:409) | |
2014/05/15 00:45:16.556 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:410) | |
2014/05/15 00:45:16.557 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.557 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.559 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.559 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.560 [D] PoiExporter#endFooter(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:78) | |
2014/05/15 00:45:16.572 [D] PoiExporter#openDocument(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:92) | |
2014/05/15 00:45:16.572 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:408) | |
2014/05/15 00:45:16.573 [D] Exporter#parseText(): Text is: | |
Rennes, le 15/05/2014 | |
(in net/bicou/upcab/ui/docs/export/Exporter.java:409) | |
2014/05/15 00:45:16.573 [D] Exporter#parseText(): ---------------------------------------------------------------- (in net/bicou/upcab/ui/docs/export/Exporter.java:410) | |
2014/05/15 00:45:16.573 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.577 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.578 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.579 [D] PoiExporter#createParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:117) | |
2014/05/15 00:45:16.579 [D] PoiExporter#addParagraphChunk(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:127) | |
2014/05/15 00:45:16.581 [D] PoiExporter#setParagraphAlignment(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:181) | |
2014/05/15 00:45:16.581 [D] PoiExporter#endParagraph(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:203) | |
2014/05/15 00:45:16.581 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.582 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.584 [D] PoiExporter#addNewLine(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:214) | |
2014/05/15 00:45:16.585 [D] PoiExporter#closeDocument(): (in net/bicou/upcab/ui/docs/export/PoiExporter.java:97) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.bicou.upcab.ui.docs.export; | |
import net.bicou.upcab.model.docs.EditableTextSectionType; | |
import net.bicou.upcab.util.L; | |
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | |
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; | |
import org.apache.poi.xwpf.usermodel.Document; | |
import org.apache.poi.xwpf.usermodel.ParagraphAlignment; | |
import org.apache.poi.xwpf.usermodel.UnderlinePatterns; | |
import org.apache.poi.xwpf.usermodel.XWPFParagraph; | |
import org.apache.poi.xwpf.usermodel.XWPFRun; | |
import org.apache.poi.xwpf.usermodel.XWPFTable; | |
import org.apache.poi.xwpf.usermodel.XWPFTableCell; | |
import org.apache.xmlbeans.XmlException; | |
import org.eclipse.swt.graphics.Rectangle; | |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; | |
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
/** | |
* Apache POI implementation, in order to export to .docx file format | |
* <p/> | |
* Created by bicou on 20/08/13. | |
*/ | |
public class PoiExporter extends Exporter { | |
private String mFileName; | |
private UCXWPFDocument mXWPFDocument; | |
private XWPFParagraph mCurrentParagraph; | |
private final List<XWPFParagraph> mHeaderParagraphs; | |
private final List<XWPFParagraph> mFooterParagraphs; | |
private String[] mRowData; | |
public PoiExporter() { | |
mHeaderParagraphs = new ArrayList<XWPFParagraph>(); | |
mFooterParagraphs = new ArrayList<XWPFParagraph>(); | |
} | |
@Override | |
protected void createDocument(final String fileName) { | |
mFileName = fileName; | |
mXWPFDocument = new UCXWPFDocument(); | |
} | |
@Override | |
protected void startHeader() { | |
} | |
@Override | |
protected void endHeader() { | |
try { | |
final CTSectPr sectPr = mXWPFDocument.getDocument().getBody().addNewSectPr(); | |
final XWPFHeaderFooterPolicy hfPolicy = new PoiHeaderFooterPolicy(mXWPFDocument, sectPr); | |
hfPolicy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, mHeaderParagraphs.toArray(new XWPFParagraph[mHeaderParagraphs.size()])); | |
} catch (final IOException e) { | |
L.e("Couldn't end header", e, L.Severity.FUNCTIONAL_FAILURE); | |
} catch (final XmlException e) { | |
L.e("Couldn't end header", e, L.Severity.FUNCTIONAL_FAILURE); | |
} | |
} | |
@Override | |
protected void startFooter() { | |
} | |
@Override | |
protected void endFooter() { | |
try { | |
final CTSectPr sectPr = mXWPFDocument.getDocument().getBody().getSectPr(); | |
final XWPFHeaderFooterPolicy hfPolicy = new PoiHeaderFooterPolicy(mXWPFDocument, sectPr); | |
hfPolicy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, mFooterParagraphs.toArray(new XWPFParagraph[mFooterParagraphs.size()])); | |
} catch (final IOException e) { | |
L.e("Coudln't end footer", e, L.Severity.FUNCTIONAL_FAILURE); | |
} catch (final XmlException e) { | |
L.e("Coudln't end footer", e, L.Severity.FUNCTIONAL_FAILURE); | |
} | |
} | |
@Override | |
protected void openDocument() { | |
} | |
@Override | |
protected void closeDocument() { | |
FileOutputStream fos = null; | |
try { | |
fos = new FileOutputStream(new File(mFileName)); | |
mXWPFDocument.write(fos); | |
} catch (final IOException e) { | |
handleError(e); | |
} finally { | |
if (fos != null) { | |
try { | |
fos.close(); | |
} catch (final IOException e) { | |
// Don't care | |
} | |
} | |
} | |
} | |
@Override | |
protected void createParagraph() { | |
if (mCurrentSection == EditableTextSectionType.BODY) { | |
mCurrentParagraph = mXWPFDocument.createParagraph(); | |
} else { | |
mCurrentParagraph = new XWPFParagraph(CTP.Factory.newInstance(), mXWPFDocument); | |
} | |
} | |
@Override | |
protected void addParagraphChunk(final String chunk, final TextDecoration style) { | |
final XWPFRun xwpfRun = mCurrentParagraph.createRun(); | |
xwpfRun.setText(chunk); | |
xwpfRun.setBold((style.style & TextDecoration.STYLE_BOLD) > 0); | |
xwpfRun.setItalic((style.style & TextDecoration.STYLE_ITALIC) > 0); | |
if ((style.style & TextDecoration.STYLE_UNDERLINE) > 0) { | |
xwpfRun.setUnderline(UnderlinePatterns.SINGLE); | |
} | |
xwpfRun.setFontSize(style.fontSize); | |
} | |
@Override | |
protected void addImage(final ImageFormat imageFormat, final String filePath, final Rectangle bounds) { | |
// Get picture format | |
final int pictureType; | |
switch (imageFormat) { | |
case PNG: | |
pictureType = Document.PICTURE_TYPE_PNG; | |
break; | |
case JPG: | |
pictureType = Document.PICTURE_TYPE_JPEG; | |
break; | |
default: | |
throw new IllegalStateException("Can't use anything else than PNG/JPG in Apache POI"); | |
} | |
// Add it | |
FileInputStream inputStream = null; | |
try { | |
inputStream = new FileInputStream(filePath); | |
final XWPFRun xwpfRun = mCurrentParagraph.createRun(); | |
final String blipId = mXWPFDocument.addPictureData(inputStream, pictureType); | |
final int nextPicNameNumber = mXWPFDocument.getNextPicNameNumber(pictureType); | |
mXWPFDocument.insertPicture(xwpfRun, blipId, nextPicNameNumber, bounds.width, bounds.height); | |
} catch (final InvalidFormatException e) { | |
L.e("Unable to add image to XWPF document", e, L.Severity.FUNCTIONAL_FAILURE); | |
} catch (final IOException e) { | |
L.e("Unable to add image to XWPF document", e, L.Severity.FUNCTIONAL_FAILURE); | |
} finally { | |
if (inputStream != null) { | |
try { | |
inputStream.close(); | |
} catch (final IOException e) { | |
L.e("Unable to close IS", e, L.Severity.WARNING); | |
} | |
} | |
} | |
} | |
@Override | |
protected void setParagraphAlignment(final TextAlignment alignment) { | |
final ParagraphAlignment align; | |
switch (alignment) { | |
case CENTER: | |
align = ParagraphAlignment.CENTER; | |
break; | |
case RIGHT: | |
align = ParagraphAlignment.RIGHT; | |
break; | |
case JUSTIFY: | |
align = ParagraphAlignment.BOTH; | |
break; | |
default: | |
case LEFT: | |
align = ParagraphAlignment.LEFT; | |
break; | |
} | |
mCurrentParagraph.setAlignment(align); | |
} | |
@Override | |
protected void endParagraph() { | |
if (mCurrentSection == EditableTextSectionType.HEADER) { | |
mHeaderParagraphs.add(mCurrentParagraph); | |
} else if (mCurrentSection == EditableTextSectionType.FOOTER) { | |
mFooterParagraphs.add(mCurrentParagraph); | |
} | |
mCurrentParagraph = null; | |
} | |
@Override | |
protected void addNewLine() { | |
mXWPFDocument.createParagraph().createRun().setText(""); | |
} | |
@Override | |
protected void createTable(final String[] rowData) { | |
mRowData = rowData; | |
} | |
@Override | |
protected void addTableRows(final String[][] cells) { | |
final int cols = mRowData.length; | |
final int rows = cells.length + 1; | |
XWPFParagraph p; | |
XWPFRun run; | |
XWPFTableCell cell; | |
String text; | |
final XWPFTable table = mXWPFDocument.createTable(rows, cols); | |
// First row | |
for (int col = 0; col < cols; col++) { | |
cell = table.getRow(1).getCell(col + 1); | |
p = cell.getParagraphs().get(0); | |
run = p.createRun(); | |
text = mRowData[col]; | |
if (text.startsWith("_")) { | |
cell.setColor(CELL_HEADER_BACKGROUND_COLOR_RRGGBB); | |
text = text.substring(1); | |
} | |
run.setText(text); | |
} | |
// Other rows | |
for (int row = 0; row < cells.length; row++) { | |
for (int col = 0; col < cols; col++) { | |
cell = table.getRow(row + 2).getCell(col + 1); | |
p = cell.getParagraphs().get(0); | |
run = p.createRun(); | |
run.setText(cells[row][col]); | |
} | |
} | |
} | |
@Override | |
public String toString() { | |
return "PoiExporter{" + | |
"mFileName='" + mFileName + '\'' + | |
", mXWPFDocument=" + mXWPFDocument + | |
", mCurrentParagraph=" + mCurrentParagraph + | |
", mHeaderParagraphs=" + mHeaderParagraphs + | |
", mFooterParagraphs=" + mFooterParagraphs + | |
", mRowData=" + Arrays.toString(mRowData) + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.bicou.upcab.ui.docs.export; | |
import net.bicou.upcab.util.L; | |
import org.apache.poi.util.Units; | |
import org.apache.poi.xwpf.usermodel.XWPFDocument; | |
import org.apache.poi.xwpf.usermodel.XWPFRun; | |
import org.apache.xmlbeans.XmlException; | |
import org.apache.xmlbeans.XmlToken; | |
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; | |
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; | |
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; | |
/** | |
* Extension of the default {@link org.apache.poi.xwpf.usermodel.XWPFDocument} class, in order to fix support for embedded images | |
* Found at http://stackoverflow.com/a/17849834/334493 | |
* Created by bicou on 14/05/2014. | |
*/ | |
public class UCXWPFDocument extends XWPFDocument { | |
public UCXWPFDocument() { | |
} | |
/** | |
* Insert a picture in the provided run. | |
* | |
* @param run The run to add the picture to | |
* @param blipId The picture blip ID | |
* @param id The picture ID | |
* @param width The picture width, in pixels (do NOT convert it to EMU) | |
* @param height The picture height, in pixels (do NOT convert it to EMU) | |
*/ | |
public void insertPicture(final XWPFRun run, final String blipId, final int id, int width, int height) { | |
width = Units.toEMU(width); | |
height = Units.toEMU(height); | |
final CTInline inline = run.getCTR().addNewDrawing().addNewInline(); | |
final String picXml = "" + | |
"<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + | |
" <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + | |
" <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + | |
" <pic:nvPicPr>" + | |
" <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" + | |
" <pic:cNvPicPr/>" + | |
" </pic:nvPicPr>" + | |
" <pic:blipFill><a:blip r:embed=\"" + blipId + "\" />" + | |
" <a:stretch>" + | |
" <a:fillRect/>" + | |
" </a:stretch>" + | |
" </pic:blipFill>" + | |
" <pic:spPr>" + | |
" <a:xfrm>" + | |
" <a:off x=\"0\" y=\"0\"/>" + | |
" <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + | |
" </a:xfrm>" + | |
" <a:prstGeom prst=\"rect\">" + | |
" <a:avLst/>" + | |
" </a:prstGeom>" + | |
" </pic:spPr>" + | |
" </pic:pic>" + | |
" </a:graphicData>" + | |
"</a:graphic>"; | |
XmlToken xmlToken = null; | |
try { | |
xmlToken = XmlToken.Factory.parse(picXml); | |
} catch (final XmlException xe) { | |
L.e("Unable to parse XML", xe, L.Severity.FUNCTIONAL_FAILURE); | |
} | |
inline.set(xmlToken); | |
inline.setDistT(0); | |
inline.setDistB(0); | |
inline.setDistL(0); | |
inline.setDistR(0); | |
final CTPositiveSize2D extent = inline.addNewExtent(); | |
extent.setCx(width); | |
extent.setCy(height); | |
final CTNonVisualDrawingProps docPr = inline.addNewDocPr(); | |
docPr.setId(id); | |
docPr.setName("Picture " + id); | |
docPr.setDescr("Generated"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment