Page 1 of 1

Export Writer page as jpeg

Posted: Thu Aug 01, 2013 5:01 pm
by eBookLuke
Hi all,

I need to export the first page of a Writer document as jpeg, via Basic macro, in the same way I can do it by using the menu File>Export and choosing "jpeg" as filetype.

I found this code, but doesn't works with Writer:

Code: Select all

Sub ExportJPG
	Dim Props(1) as New com.sun.star.beans.PropertyValue
	oSM = GetProcessServiceManager
	ExportSrv = oSM.createInstance("com.sun.star.drawing.GraphicExportFilter")
	oDPages = oTextDoc.getDrawPage()
	oPage = oDPages.getByIndex(1)
	ExportSrv.setSourceDocument(oTextDoc)
	Props(0).Name = "MediaType"
	Props(0).Value = "image/jpeg"
	Props(1).Name = "URL"
	Props(1).Value = "file:///C:/Exported.jpg"
	ExportSrv.filter(Props)
End Sub
Someone can help me?

Thanks

Luke

Re: Export Writer page as jpeg

Posted: Sat Aug 03, 2013 3:18 pm
by F3K Total
Hi,
eBookLuke wrote:Writer document as jpeg, via Basic macro, in the same way I can do it by using the menu File>Export and choosing "jpeg" as filetype
For sure?
I can't find "jpeg" as an export Option in Writer:
x.png
x.png (6.18 KiB) Viewed 4490 times
That's all
R

Re: Export Writer page as jpeg

Posted: Sun Aug 04, 2013 8:49 pm
by eBookLuke
True, I confused Apache OpenOffice with LibreOffice that has this featureā€¦ :(

Anyway, suggestions about exporting Writer pages in jpg?

Re: Export Writer page as jpeg

Posted: Tue Nov 12, 2019 2:11 pm
by Ahham
Hello,

for me it works: :D in draws

Code: Select all

Sub ExportJPG
Dim oDPages As Object
dim oDoc
Dim oSm
dim ExportSrv
dim oPage
Dim URL As String
   Dim Props(1) as New com.sun.star.beans.PropertyValue
   oDoc = ThisComponent
   oSM = GetProcessServiceManager
   ExportSrv = oSM.createInstance("com.sun.star.drawing.GraphicExportFilter") 
   oPage = oDoc.DrawPages(0)
   ExportSrv.setSourceDocument(oPage)
   URL = "C:\Example\Exported2.jpg"
   Props(0).Name = "MediaType"
   Props(0).Value = "image/jpeg"
   Props(1).Name = "URL"
   Props(1).Value = ConvertToUrl(URL)
   ExportSrv.filter(Props)
End Sub