LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 04-27-2006, 02:13 PM   #1
yumener
Member
 
Registered: Oct 2005
Posts: 63

Rep: Reputation: 15
convert doc to pdf in command line


some people may ask me to refer to this link

http://www.oooforum.org/forum/viewtopic.phtml?t=3772

I followed it in Linux (FC5), but I got a problem when the
code run to

oDoc.storeToURL( cURL, Array(_
MakePropertyValue( "FilterName", "writer_pdf_Export" ),_
)

I have made sure cURL is correct, this line always threw up an error message. Seems nobody have given a solution.

anybody know how can I solve this problem?

thanks.
 
Old 04-27-2006, 02:29 PM   #2
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 50
try looking again at the API(is it python or qbasic?). I think you are in the right way though.
 
Old 04-27-2006, 04:44 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Are you sure you don't have any spaces anywhere in the file name when you call from the command line?

What is the error message you get?

This is my code:

Code:
Sub SaveDocAsPDF( cFile )
	Dim oDoc as object
   	   	
   	cURL = ConvertToURL( cFile )
   	' Open the document. Just blindly assume that the document 
   	' is of a type that OOo will correctly recognize and open 
   	' without specifying an import filter.
   	oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
    	Array(MakePropertyValue( "Hidden", True ),))
            
   cFile = Left( cFile, Len( cFile ) - 4 )
   cURL = ConvertToURL( cFile + ".pdf" )
   
   ' Save the document using a filter.   
	oDoc.storeToURL( cURL, Array( MakePropertyValue( "FilterName", "writer_pdf_Export" ) ) )
   
   oDoc.close( True )
End Sub
And:

Code:
Function MakePropertyValue( Optional cName As String, Optional uValue ) _
   As com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New 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
This is the command line I use (from a script)

Code:
$OOFFICE -invisible "macro:///Standard.Conversions.SaveDocAsPDF($local_dir$fname.doc)"
The should be NO spaces between the parenthesis, like
SaveDocAsPDF( wrong ) because the the macro will try to open " wrong "
Note the spaces.

jlinkels
 
Old 04-28-2006, 04:38 AM   #4
yumener
Member
 
Registered: Oct 2005
Posts: 63

Original Poster
Rep: Reputation: 15
Thumbs up

I am sure there is no space like what you said.
actually I have two problem

the first is if I copy your code or the one in my first post,
I always got a wrong cURL when run to

Sub SaveDocAsPDF( cFile )
Dim oDoc as object

cURL = ConvertToURL( cFile )
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0,
.... //error here because cURL is wrong

To remove this error, I hardcoded cURL of BOTH of doc file
and pdf file like
cURL = "file:///home/me/test.doc"
cURL = "file:///home/me/test.pdf"

so now the cURL should be alright but it always threw out error message at this line of code

oDoc.storeToURL( cURL, Array( MakePropertyValue( "FilterName", "writer_pdf_Export" ) ) )

###error message####
BASIC runtime error
an exception occurred
Type: com.sun.star.task.ErrorCodeIOException
Message:.
###end of message###

i.e, message is a dot. I do not know what is happening here.






Quote:
Originally Posted by jlinkels
Are you sure you don't have any spaces anywhere in the file name when you call from the command line?

What is the error message you get?

This is my code:

Code:
Sub SaveDocAsPDF( cFile )
	Dim oDoc as object
   	   	
   	cURL = ConvertToURL( cFile )
   	' Open the document. Just blindly assume that the document 
   	' is of a type that OOo will correctly recognize and open 
   	' without specifying an import filter.
   	oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
    	Array(MakePropertyValue( "Hidden", True ),))
            
   cFile = Left( cFile, Len( cFile ) - 4 )
   cURL = ConvertToURL( cFile + ".pdf" )
   
   ' Save the document using a filter.   
	oDoc.storeToURL( cURL, Array( MakePropertyValue( "FilterName", "writer_pdf_Export" ) ) )
   
   oDoc.close( True )
End Sub
And:

Code:
Function MakePropertyValue( Optional cName As String, Optional uValue ) _
   As com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New 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
This is the command line I use (from a script)

Code:
$OOFFICE -invisible "macro:///Standard.Conversions.SaveDocAsPDF($local_dir$fname.doc)"
The should be NO spaces between the parenthesis, like
SaveDocAsPDF( wrong ) because the the macro will try to open " wrong "
Note the spaces.

jlinkels
 
Old 04-28-2006, 09:23 AM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,236

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
This is gonna be a tough one, isn't it? When the code runs on one machine and is supposedly correct, it is difficult to change it into something else which is correct as well.

There might be a few things to narrow down where the error is.

1. Don't open the document as "hidden". Now you can see if the document is opened correctly. Use this call:
Code:
oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array()
2. If the document opens correctly, try to do another operation on oDoc. I don't know which one for a writer document, but you should be able to find something in the forum you referred to before. If you do that, you know for sure oDoc has a value and can be used.
3. In any way, single step thru your code and inspect all objects if possible. There is a tool available which you can use to inspect objects, X-ray or so. You'll find pointers on that same forum.
4. Single step thru the MakePropertyValue function to see if everything is set and returned as expected.

Almost all problems I had with these kind of macros is that I tried to use something which was not there, like to open a non-existent file, or to select a non existent sheet in a workbook, or to store something in a non-existent directory.

The cURL you specified looks good. Did you try to get cURL from
Code:
cURL=ConvertToURL
as well? Is it the same?

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Software to automatically convert DOC into PDF rsmccain Linux - Software 3 11-23-2006 11:19 AM
Convert .DOC into .PDF automatically MPANDYA Linux - Software 2 11-08-2005 09:34 AM
command line utility to convert between formats like .doc, .sxw, .rtf and others? bigtpumped Linux - Software 1 09-12-2005 10:54 PM
trouble finding policy doc as pdf in doc mirrors stardotstar Debian 2 05-12-2005 11:56 PM
how to convert pdf file to doc format. thushara Linux - Newbie 3 03-22-2005 07:29 AM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration