在LibreOffice中,当您打印(不导出为PDF)时,可以选择在边距中显示文档的注释 . 然后,您可以选择PDF打印机并获取带有边距注释的PDF . 我试图以编程方式获取具有注释的ODT文件,并生成带有边距注释的PDF . 我已经能够成功生成PDF,但无法弄清楚如何显示评论 . 在边距中显示注释是可取的,但在每页底部显示为摘要也是可以接受的 . 该应用程序将在Ubuntu服务器上运行 . 我正在尝试从Java,Python或通过Linux脚本执行此操作 .
我得到的最接近的是来自官方LibreOffice api开发人员指南的这个java示例,但是找不到用于设置或修改打印机对话框中的打印选项的属性值,可以在打印机对话框中手动设置 .
public class DocumentPrinter {
public static void main(String args[]) {
if ( args.length < 3 ) {
System.out.println("usage: java -jar DocumentLoader.jar " +
"\"<Favoured printer>\" \"<URL|path>\" \"<Pages>\"");
System.out.println( "\ne.g.:" );
System.out.println("java -jar DocumentLoader.jar \"amadeus\" " +
"\"file:///f:/TestPrint.odt\" \"1-3;7;9\"");
System.exit(1);
}
com.sun.star.uno.XComponentContext xContext = null;
try {
// get the remote office component context
xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
System.out.println("Connected to a running office ...");
// get the remote office service manager
com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext);
com.sun.star.frame.XComponentLoader xCompLoader =
UnoRuntime.queryInterface(
com.sun.star.frame.XComponentLoader.class, oDesktop);
java.io.File sourceFile = new java.io.File(args[1]);
StringBuffer sUrl = new StringBuffer("file:///");
sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
// Load a Writer document, which will be automatically displayed
com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
sUrl.toString(), "_blank", 0,
new com.sun.star.beans.PropertyValue[0] );
// Querying for the interface XPrintable on the loaded document
com.sun.star.view.XPrintable xPrintable =
UnoRuntime.queryInterface(
com.sun.star.view.XPrintable.class, xComp);
// Setting the property "Name" for the favoured printer (name of
// IP address)
com.sun.star.beans.PropertyValue propertyValue[] =
new com.sun.star.beans.PropertyValue[1];
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Name";
propertyValue[0].Value = args[ 0 ];
// Setting the name of the printer
xPrintable.setPrinter( propertyValue );
// Setting the property "Pages" so that only the desired pages
// will be printed.
propertyValue[0] = new com.sun.star.beans.PropertyValue();
propertyValue[0].Name = "Pages";
propertyValue[0].Value = args[ 2 ];
// Printing the loaded document
xPrintable.print( propertyValue );
System.exit(0);
}
catch( Exception e ) {
e.printStackTrace(System.err);
System.exit(1);
}
}
}
我尝试过的另一条路线是registrymodifications.xcu文件 . 我试图在更改文档中的打印设置时复制和比较文件,以查看特定设置是否更改 . 没有任何结果 .
我也尝试通过文件的odt存档中的settings.xml文件进行阅读 . 有一些与打印相关的属性,但似乎与评论无关 .
我已经搜索了Stack Overflow和Google数小时无济于事 . 任何有关以编程方式设置/更改与评论相关的打印机设置的信息都将非常受欢迎 .