Page 1 of 1

Embedding Office files

PostPosted: Wed Aug 13, 2014 6:37 pm
by vinaykadiyam
Hi Jason,

I have few questions related this post.

Whiel doing some poc on plutext with trial version, I could insert ole objects into word. But could help us here for below information.

1. How can I insert a .doc file into word means as an ole or can we read the stream of it and insert into word ?
2. How can I insert a .xsl or .xslx file into docx4j?
3. We could insert vdx file or ole into word. But after clicking on object we could open the file. But, after click the image of the ole in generated doc is becoming low (please see attached doc for the reference).
4. Could you suggest how can we proceed for otherthan OLE objects.

Thanks,
Vinay

Re: Embedding Office files

PostPosted: Fri Aug 15, 2014 9:59 pm
by jason
Hi Vinay

vinaykadiyam wrote:1. How can I insert a .doc file into word means as an ole


I think you know how to do this? See the Docx_ole_Doc sample. Or when you say "word" do you mean automating the Microsoft Word application?

vinaykadiyam wrote:can we read the stream of it and insert into word ?


The API (OleHelperDocx) takes the doc file contents as a byte array, so you need to convert your stream to a byte[]

vinaykadiyam wrote:2. How can I insert a .xsl or .xslx file into docx4j?


For .xls, use EmbeddingType.XLS

For .xlsx, we currently don't provide the code to do this, since it is relatively straightforward (the xlsx file doesn't need to be converted to an OLE object, it is just embedded as a binary). That said, for completeness, we'll add it.

vinaykadiyam wrote:3. We could insert vdx file or ole into word. But after clicking on object we could open the file. But, after click the image of the ole in generated doc is becoming low (please see attached doc for the reference).


When you say "low", you mean the image shrinks? Or something else? To explore this further, you can email support@plutext.com

We'll need code and input to reproduce, along with the exact version of Word you are seeing this in.

vinaykadiyam wrote:4. Could you suggest how can we proceed for otherthan OLE objects.


You mean OLE embedding objects of file types we don't currently support? We can add support on a case by case basis. At minimum, you need to provide a sample file with a file of that type embedded in a docx/pptx or xlsx. You can generally create that by using Office on a PC with the relevant application installed. In Word, you use Insert > Object.

Re: Embedding Office files

PostPosted: Mon Aug 18, 2014 10:14 pm
by vinaykadiyam
Hi Jason,

Thanks for the reply.

1. I have gone through Docx_ole_Doc sample. But in that .doc is attached as either a link or an embed. But I want to merge the contents of the .doc file to generated .docx file. Is this possible? if answer is yes, How can I do that?

2. When can we expect insertion of xslx into docx?

3. Yes you are right, when we click on a icon it is shrinking (Please find attached generated doc).

private void addOleObjectToPackage(
WordprocessingMLPackage mlPackageWriteOnly2, byte[] bytes,
String fileType, String filePath, String caption) {
EmbeddingType embeddingType = null;
try {
embeddingType = EmbeddingType.valueOf(fileType);
} catch (IllegalArgumentException iae) {
embeddingType = EmbeddingType.TXT;
}

int index = -1;

byte[] imageBytes = null;
// 1. Fetch Rule Binary file from DB
ClipboardPage binaryImageFile = null;
StringMap keys = new HashStringMap();
String mime = null;
if ("vdx".equalsIgnoreCase(fileType)) {
keys.putString("pxObjClass", "Rule-File-Binary");
keys.putString("pyApplicationName", "webwb");
keys.putString("pyFileName", "openvisiolarge");
keys.putString("pyFileType", "png");
mime = "image/png";

} else if ("doc".equalsIgnoreCase(fileType)) {
keys.putString("pxObjClass", "Rule-File-Binary");
keys.putString("pyApplicationName", "webwb");
keys.putString("pyFileName", "pyWordDoc");
keys.putString("pyFileType", "png");
mime = "image/png";

} else if ("xslx".equalsIgnoreCase(fileType)
|| "xslx".equalsIgnoreCase(fileType)) {
keys.putString("pxObjClass", "Rule-File-Binary");
keys.putString("pyApplicationName", "webwb");
keys.putString("pyFileName", "pyExcelDoc");
keys.putString("pyFileType", "png");
mime = "image/png";

} else if ("pdf".equalsIgnoreCase(fileType)) {
keys.putString("pxObjClass", "Rule-File-Binary");
keys.putString("pyApplicationName", "webwb");
keys.putString("pyFileName", "pyCreatePDFAPIIcon");
keys.putString("pyFileType", "png");
mime = "image/png";

} else {

keys.putString("pxObjClass", "Rule-File-Binary");
keys.putString("pyApplicationName", "webwb");
keys.putString("pyFileName", "pzPreview");
keys.putString("pyFileType", "png");
mime = "image/png";

}
try {
binaryImageFile = localTools.getDatabase().open(keys, true);
} catch (DatabaseException dbEx) {
oLog.error("Error opening file: ", dbEx);
}
// TODO Change it to point to correct icon based upon the file type
String strFileData = binaryImageFile.getString("pyFileSource");
imageBytes = Base64Util.decodeToByteArray(strFileData);

// TODO change it to point to temp location of the server
// String fileLoc =
String command = filePath + caption + "." + fileType; // a temp file
// For link only
// String targetURL = "file:///" + command;
if ("pdf".equals(fileType)) {
com.plutext.ole.pdf.PdfOleHelperDocx pdfOleHelper = new com.plutext.ole.pdf.PdfOleHelperDocx(
mlPackageWriteOnly2);
try {
pdfOleHelper.embedUsingIcon(bytes, -1, caption);
} catch (com.plutext.ole.OLEException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if ("odf".equals(fileType)) {
com.plutext.ole.odf.OdfOleHelperDocx odfOleHelper = new com.plutext.ole.odf.OdfOleHelperDocx(
mlPackageWriteOnly2);
try {
odfOleHelper.embedUsingIcon(embeddingType, bytes, -1, caption);
} catch (com.plutext.ole.OLEException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

} else {
com.plutext.ole.OleHelperDocx OleHelperDocx = new com.plutext.ole.OleHelperDocx(
mlPackageWriteOnly2);
try {
OleHelperDocx.embed(index, embeddingType, caption, filePath,
command, bytes, imageBytes, mime,
"width:32pt;height:32pt");
} catch (com.plutext.ole.OLEException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


Regards,
Vinay

Re: Embedding Office files

PostPosted: Mon Aug 18, 2014 10:40 pm
by jason
vinaykadiyam wrote:1. I have gone through Docx_ole_Doc sample. But in that .doc is attached as either a link or an embed. But I want to merge the contents of the .doc file to generated .docx file. Is this possible? if answer is yes, How can I do that?


When you say "merge", do you mean concatenate or diff/merge changes? Whichever you mean, for docx4j to help, first you need to convert the doc to docx. That is largely outside the scope of docx4j (although there is a rudimentary proof of concept, using POI's HWPF stuff). If you can't use Word, alternatives are to use LibreOffice/OpenOffice or perhaps Google Docs.

vinaykadiyam wrote:2. When can we expect insertion of xslx into docx?


I hope to have a chance to write the sample code tomorrow

vinaykadiyam wrote:3. Yes you are right, when we click on a icon it is shrinking (Please find attached generated doc).


I've only just glanced at your code, but I suspect its because you specify "width:32pt;height:32pt":

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
OleHelperDocx.embed(index, embeddingType, caption, filePath,
command, bytes, imageBytes, mime,
"width:32pt;height:32pt");
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4

Re: Embedding Office files

PostPosted: Mon Aug 18, 2014 11:09 pm
by vinaykadiyam
3. Shrinking is happening without mentioning a size to icon. We have tried this with and without but no luck. Do let us know if you have any information or suggestionon this.

Thanks,
Vinay

Re: Embedding Office files

PostPosted: Wed Aug 20, 2014 12:24 am
by jason
Regarding embedding xlsx in docx, sample code to do this is included in Enterprise-3.2.0-beta2

The sample is named Docx_ole_Xlsx.

You can download it from http://www.plutext.com/dn/downloads/140 ... -trial.zip

Please use it in conjunction with docx4j-3.2.0-beta2.jar

http://www.docx4java.org/docx4j/docx4j-3.2.0-beta2.jar

cheers .. Jason

Re: Embedding Office files

PostPosted: Tue Feb 09, 2016 7:56 pm
by shabeer
Is embedding PDF inside MS Word requires Licensed version or will it work with trial version.

Re: Embedding Office files

PostPosted: Thu Feb 11, 2016 1:46 am
by jason
You can try it with the trial version. It'll work, but eventually it'll print text saying its a trial...