Dear 龚 文益,
thank you for contacting us.
Currently, a TEXT part can only be exported as TEXT, JIIX, JPEG or PNG.
Before calling the export_ function, we recommend you call the "getSupportedExportMimeTypes" function. You will then know if a given block can be exported in a given type.
In your current use-case, if you want to export a docx, the solution consists in copying the part, paste it into a Text Document part and export the latter to docx.
Best regards,
Olivier
谢谢
Write down the code according to your reminder.
new Thread() {
@Override
public void run() {
super.run();
try {
Editor editor = editorView.getEditor();
editor.copy(editor.getRootBlock());
ContentPart contentPart = mMyScriptScrvice.getContentPart();
ContentPackage contentPackage = mMyScriptScrvice.getContentPackage();
ContentPart contentPart2 = contentPackage.createPart("Text Document");//创建文件
editor.setPart(contentPart2);
editorView.invalidate(editor.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class));
editor.paste(10, 10);
sleep(200);
ContentBlock rootBlock = editor.getRootBlock();
ContentBlock[] children = rootBlock.getChildren();
if (children.length == 0) {
showToast("失败");
return;
}
ContentBlock block = children[0];
MimeType[] mimeTypes = editor.getSupportedExportMimeTypes(block);
for (MimeType mt : mimeTypes) {
MyLog.log("mimeTypes:" + mt.toString());
}
String fileName = "myTemp.docx";
// File file = new File(Environment.getExternalStorageDirectory().getPath(), fileName);
File file = new File(getFilesDir(), fileName);
if (file.exists()) {
file.delete();
}
ImageDrawer imageDrawer = new ImageDrawer();
imageDrawer.setImageLoader(editorView.getImageLoader());
editor.waitForIdle();
// editor.export_(block, file, imageDrawer);
MyLog.log("f:" + file.getPath());
MyLog.log("f:" + file.exists());
// editor.export_(editor.getRootBlock(), file, imageDrawer);
editor.export_(block,file, MimeType.DOCX, imageDrawer);
MyLog.log("f1:" + file.exists());
CallOtherOpeanFile.openFile(DrawingActivity.this,file);
editor.setPart(contentPart);
editorView.invalidate(editor.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class));
contentPackage.removePart(contentPart2);
} catch (IOException e) {
e.printStackTrace();
MyLog.log(e);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}.start();
The following exception is reported in version 1.2.2
java.lang.IllegalStateException: paste failed: content of the clipboard cannot be pasted
In version 1.2.5, the display was not saved to the device.
Is there any way to solve it?
Dear 龚 文益,
currently, where is the IllegalStateException occuring in your code? Indeed, we do not see any reason your copy/paste would not work.
Best regards,
Olivier
龚 文益
I want to export the docx file in Text mode and save the docx file path.
So I wrote the following code:
Editor editor = editorView.getEditor();
ContentBlock rootBlock = editor.getRootBlock();
ImageDrawer imageDrawer = new ImageDrawer();
imageDrawer.prepareImage(editorView.getWidth(), editorView.getHeight());
imageDrawer.setImageLoader(editorView.getImageLoader());
imageDrawer.invalidate(editorView.getRenderer(), EnumSet.allOf(IRenderTarget.LayerType.class));
File file = new File(getFilesDir()+"/export.docx");
editor.export_(rootBlock,file,imageDrawer);
Log.v("export","f.exists():"+file.exists());
But I got this exception: Caused by: java.lang.IllegalArgumentException: unrecognized file extension
Please tell me how to write, thank you.