以前我问过如何将 LibreOffice Writer 文档的所有页面导出为图像。我有这个答案。
我已经根据我的需要调整了宏,这是我当前的代码:
Sub StoreEachPageToWebP()
Dim oDoc As Variant, oViewCursor As Variant
Dim iPageCount As Long, iPage As Long
Dim sOriginalURL As String, sFileURL As String
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FilterName"
args1(0).Value = "writer_webp_Export"
args1(1).Name = "FilterData"
args1(1).Value = Array(Array("Quality",0,75,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Lossless",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelWidth",0,1000,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelHeight",0,647,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalWidth",0,26455,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalHeight",0,17116,com.sun.star.beans.PropertyState.DIRECT_VALUE))
oDoc = ThisComponent
iPageCount = oDoc.getCurrentController().PageCount
oViewCursor = oDoc.getCurrentController().getViewCursor()
sOriginalURL = oDoc.getURL()
oViewCursor.jumpToFirstPage()
For iPage = 1 To iPageCount
sFileURL = Replace(sOriginalURL, ".odt", "-" & Format(iPage, "000") & ".webp")
oDoc.StoreToURL(sFileURL, args1)
If Not oViewCursor.jumpToNextPage() Then End
Next iPage
End Sub
不幸的是FilterData
,选项似乎被忽略了。导出的 WebP 图像始终具有相同的分辨率,即页面的标准尺寸。当我手动导出它时,它可以工作。我已经使用录制的宏来获取选项,FilterData
因此我可以确定它们是正确的。录制的宏如下所示:
sub RecordedPageExportAsWebP
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///home/user/Documents/namecards-all.webp"
args1(1).Name = "FilterName"
args1(1).Value = "writer_webp_Export"
args1(2).Name = "FilterData"
args1(2).Value = Array(Array("Quality",0,75,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Lossless",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelWidth",0,1000,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PixelHeight",0,647,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalWidth",0,26455,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("LogicalHeight",0,17116,com.sun.star.beans.PropertyState.DIRECT_VALUE))
args1(3).Name = "SelectionOnly"
args1(3).Value = false
dispatcher.executeDispatch(document, ".uno:ExportTo", "", 0, args1())
end sub
我在这里想念什么?
我正在使用以下版本的 LibreOffice:
Version: 7.4.0.3 / LibreOffice Community
Build ID: 40(Build:3)
CPU threads: 8; OS: Linux 5.19; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
7.4.0-3
Calc: threaded