OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

hidden document cause OOo crash (storeToURL)

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
sunway
Newbie
Newbie


Joined: 26 Aug 2004
Posts: 2

PostPosted: Wed Jan 12, 2005 1:32 am    Post subject: hidden document cause OOo crash (storeToURL) Reply with quote

Hi:
I want to convert OOo documents to pdf.
I execute the following macro in terminal. eg:
soffice "macro:///Standard.Module1.Test(/tmp/1.sxw)"

Mandrake 9 / OOo 1.1.0
.sxw/.sxm cause OOo crash.
------------------
On Windows 2000 / OOo 1.1.2
.sxw is OK.
.sxm , new created pdf file is empty !!
---------------------
[code]
Sub Test(strFile as string)
Dim oDoc as Object
Dim strFilterSubName as String

oDoc = StarDesktop.loadComponentFromURL( ConvertToUrl( strFile ), "_blank", 0, array(MakePropertyValue("Hidden",true)))

If not IsNull(oDoc) Then
strFilterSubName = ""
' select appropriate filter
If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
strFilterSubName = "impress_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
strFilterSubName = "calc_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
strFilterSubName = "writer_web_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
strFilterSubName = "writer_globaldocument_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
strFilterSubName = "writer_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
strFilterSubName = "draw_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
strFilterSubName = "math_pdf_Export"
ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
strFilterSubName = "chart_pdf_Export"
Else
'
EndIf

If Len(strFilterSubName) > 0 Then
oDoc.storeToUrl( ConvertToUrl( strFile & ".pdf" ), array(MakePropertyValue("FilterName", strFilterSubName ),MakePropertyValue("CompressMode", "1" )))
EndIF
EndIf

oDoc.close(True)

End Sub
[/code]

best regards
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Jan 12, 2005 7:07 am    Post subject: Reply with quote

This causes me NO problems when run on Windows using 1.1.3. I only tried both a large and a small document from the command line. I already had Ooo running, when I tried this, however.

Code:
Sub ExportAsPDF(strFile as string)
  Dim oDoc
  Dim strFilterSubName as String
  Dim oLoadArgs(0) as New com.sun.star.beans.PropertyValue

  oLoadArgs(0).Name  = "Hidden"
  oLoadArgs(0).Value = True

  oDoc = StarDesktop.loadComponentFromURL(ConvertToUrl(strFile), "_blank", 0, oLoadArgs())
  If IsNull(oDoc) Then Exit Sub

  strFilterSubName = ""
  ' select appropriate filter
  If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
    strFilterSubName = "impress_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
    strFilterSubName = "calc_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
    strFilterSubName = "writer_web_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
     strFilterSubName = "writer_globaldocument_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
    strFilterSubName = "writer_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
    strFilterSubName = "draw_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
    strFilterSubName = "math_pdf_Export"
  ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
    strFilterSubName = "chart_pdf_Export"
  Else
    Exit Sub
  EndIf

  Dim oSaveArgs(1) as New com.sun.star.beans.PropertyValue
  oSaveArgs(0).Name = "FilterName"
  oSaveArgs(0).Value = strFilterSubName

  oSaveArgs(1).Name = "CompressMode"
  oSaveArgs(1).Value = "1"

  oDoc.storeToUrl(ConvertToUrl( strFile & ".pdf" ), oSaveArgs())
  oDoc.close(True)
End Sub

_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Jan 14, 2005 7:15 am    Post subject: Reply with quote

I slightly edited your macro.
Code:
Sub Test(strFile as string)
   Dim oDoc as Object
   Dim strFilterSubName as String
   
   strUrl = ConvertToUrl( strFile )
   oDoc = StarDesktop.loadComponentFromURL( strUrl, "_blank", 0, array(MakePropertyValue("Hidden",true)))
   
   If not IsNull(oDoc) Then
      strFilterSubName = ""
      ' select appropriate filter
      If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
         strFilterSubName = "impress_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
         strFilterSubName = "calc_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
         strFilterSubName = "writer_web_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
         strFilterSubName = "writer_globaldocument_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
         strFilterSubName = "writer_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
         strFilterSubName = "draw_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
         strFilterSubName = "math_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
         strFilterSubName = "chart_pdf_Export"
      Else
         '
      EndIf
   EndIf
   
   If Len(strFilterSubName) > 0 Then
      oDoc.storeToUrl( ConvertToUrl( strFile & ".pdf" ), array(MakePropertyValue("FilterName", strFilterSubName ),MakePropertyValue("CompressMode", "1" )))
   EndIf
   
   oDoc.close(True)
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function


I tried this on two different systems.

Win XP Pro SP2; OOo 1.1.4; 1 GB / 80 GB

I used this command in the Windows shell....
Code:
"C:\Program Files\OpenOffice.org1.1.4\program\soffice.exe" "macro:///Standard.Module1.Test(C:\Documents and Settings\dbrewer\Desktop\Test\test.sxw)"


It worked perfectly. Generated a PDF. Opened that PDF in Adobe Acrobat 5.0 on Windows.

SuSE Linux 9.1; OOo 1.1.1; 256 MB / 120 GB

I used this command at the bash prompt....
Code:
/opt/OpenOffice.org/program/soffice "macro:///Standard.Module1.Test(/home/danny/Desktop/Test/test.sxw)"


Again, worked perfectly. Generated a PDF.
I opened that PDF in....

  • Adobe Acrobat Reader 5.0 for Linux
  • KPDF
  • KGhostView


(VNC is wonderful. Very cold. It has rocks.)

I like the way that you wrote your macro. Very nice approach. Determine which export filter to use based on document type, with a large variety of cases. This technique could be extended. Suppose I want to be able to export to either PDF or HTML. One could extend this so that the matrix of filters to export type / document type could even be listed in a table.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
kontorotsui
Newbie
Newbie


Joined: 02 Dec 2005
Posts: 1
Location: Pisa, Italy

PostPosted: Fri Dec 02, 2005 3:12 am    Post subject: Reply with quote

Hello, I'm trying to use OOo to convert its documents and HTML documents into PDF.
I tried the above macro and works perfectly Very Happy

If I call it with a .html file, I get the correct PDF version, index.html.pdf, including the images. Suppose I would also like to do the same with URL. Is it possible to extend this macro to work also with an URL?

Something like:

ooffice -invisible -headless "macro:///Standard.Module1.PDFConverter("http://www.google.it", "out.pdf")"

Best regards.
Andrea.
Back to top
View user's profile Send private message
beethoven2
Newbie
Newbie


Joined: 18 Apr 2006
Posts: 3

PostPosted: Tue Apr 18, 2006 6:31 am    Post subject: Error using this macro, please help!!! Reply with quote

When executing by command line as described

soffice.exe "macro:///Standard.Module1.Test(C:\temp\test.doc)"

i get this exception:

Error runtime basic
An exception occurred
Type:com.sun.star.task.ErrorCodeIOException
Message:.

on this line:
oDoc.storeToUrl( ConvertToUrl( strFile & ".pdf" ), array(MakePropertyValue("FilterName", strFilterSubName ),MakePropertyValue("CompressMode", "1" )))

I'm using OO 2.0.2, please help me, I wanted to convert a document readable by openoffice into PDF using command line.

I used this code for the macro:
Code:

Sub Test(strFile as string)
   Dim oDoc as Object
   Dim strFilterSubName as String
   
   strUrl = ConvertToUrl( strFile )
   oDoc = StarDesktop.loadComponentFromURL( strUrl, "_blank", 0, array(MakePropertyValue("Hidden",true)))
   
   If not IsNull(oDoc) Then
      strFilterSubName = ""
      ' select appropriate filter
      If oDoc.SupportsService("com.sun.star.presentation.PresentationDocument") Then
         strFilterSubName = "impress_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") Then
         strFilterSubName = "calc_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.WebDocument") Then
         strFilterSubName = "writer_web_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.GlobalDocument") Then
         strFilterSubName = "writer_globaldocument_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.text.TextDocument") Then
         strFilterSubName = "writer_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.drawing.DrawingDocument") Then
         strFilterSubName = "draw_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.formula.FormulaProperties") Then
         strFilterSubName = "math_pdf_Export"
      ElseIf oDoc.SupportsService("com.sun.star.chart.ChartDocument") Then
         strFilterSubName = "chart_pdf_Export"
      Else
         '
      EndIf
   EndIf
   
   If Len(strFilterSubName) > 0 Then
      oDoc.storeToUrl( ConvertToUrl( strFile & ".pdf" ), array(MakePropertyValue("FilterName", strFilterSubName ),MakePropertyValue("CompressMode", "1" )))
   EndIf
   
   oDoc.close(True)
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function


Thank you all for the future help, sorry, i'm a newbie and maybe the question will be stupid.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group