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

Draw - exporting and printing

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





PostPosted: Fri Oct 31, 2003 5:17 am    Post subject: Draw - exporting and printing Reply with quote

Hello

I don 't understand the sdk api, so I hope that anyone can help me to solve my problem.

I am a beginner and try to program a makro that exports my current draw-sheet to jpg.
if it succeeds the previous saved file has to be printed out.

Is this possible?

This is needed cause my old printer cannot print out foreign-letters.

Thanks in advance.

Aho
Back to top
DannyB
Moderator
Moderator


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

PostPosted: Fri Oct 31, 2003 12:03 pm    Post subject: Reply with quote

The biggest challenge is to learn the API. Explore the Macros and API forum here and you'll find a wealth of information.

In the meantime try putting this code directly into the macro of a drawing document. Change the pathnames or printer queue names as appropriate.

Code:
Sub Main
   cDestFolder = "/home/danny/Desktop" ' for danny's Linux at home.
'   cDestFolder = "c:\documents and settings\dbrewer\Desktop" ' for danny's WinXP at office.
   cFilename = "Drawing"
   
   oDrawDoc = ThisComponent
   
   ' Save the current document as an SXD file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".sxd" )
   oDrawDoc.storeAsURL( cURL, Array() )
   
   ' Save the current document as an EPS file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".eps" )
   oDrawDoc.storeToURL( cURL,_
      Array( MakePropertyValue( "FilterName", "draw_eps_Export" ) ) )
   
   ' Save the current document as an PDF file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".pdf" )
   oDrawDoc.storeToURL( cURL,_
      Array( MakePropertyValue( "FilterName", "draw_pdf_Export" ) ) )
   
   ' Save the current document as an JPG file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".jpg" )
   oDrawDoc.storeToURL( cURL,_
      Array( MakePropertyValue( "FilterName", "draw_jpg_Export" ) ) )
   
   ' Save the current document as an PNG file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".png" )
   oDrawDoc.storeToURL( cURL,_
      Array( MakePropertyValue( "FilterName", "draw_png_Export" ) ) )
   
   ' Save the current document as an SVG file.
   cURL = ConvertToURL( cDestFolder + "/" + cFilename + ".svg" )
   oDrawDoc.storeToURL( cURL,_
      Array( MakePropertyValue( "FilterName", "draw_svg_Export" ) ) )
   
   ' Decide which print queue to use -- on Windows.
   ' Specify any combination of properties from the
   '  com.sun.star.view.PrinterDescriptor.
   ' This step is actually unnecessary.
'   oDrawDoc.setPrinter( Array(_
'      MakePropertyValue( "Name", "\\DC01\HP 5si" ) ) )
   
   ' Decide which print queue to use -- on Linux.
   ' Specify any combination of properties from the
   '  com.sun.star.view.PrinterDescriptor.
   ' This step is actually unnecessary.
   oDrawDoc.setPrinter( Array(_
      MakePropertyValue( "Name", "lp" ) ) )
   
   ' Print the document the easy way.
'   oDrawDoc.print( Array() )
   
   ' Print the document the exciting way.
   ' Specify any combination of properties from the
   '  service com.sun.star.view.PrintOptions.
   oDrawDoc.print( Array(_
      MakePropertyValue( "CopyCount", 1 ),_
      MakePropertyValue( "Collate", True ),_
      MakePropertyValue( "Pages", "1-4;10" ) ) )
End Sub


'   Create and return a new com.sun.star.beans.PropertyValue.
'
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

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Beginner
Guest





PostPosted: Mon Nov 03, 2003 7:24 am    Post subject: Export works well Reply with quote

Hello

Thank you very much for your reply.

It brings me a step forward. The Export works well. But I have still a problem with the printing.

What I want is, to print the exported JPG-File, not the current Draw-Document.

Are their possiblities?

I tried:
Code:

sub TestExport
   myDoc = thisComponent
   Dim myProps(0) as New com.sun.star.beans.PropertyValue
   Dim iNumber as integer
   
   sURL = "file:///C:/temp/test.jpg"
   myProps(0).name="FilterName"
   myProps(0).value="draw_jpg_Export"
   
   myDoc.storeToURL(sURL, myProps())     
   Dim oProp()
  ' open previous saved document
   oNewDoc=StarDesktop.loadComponentFromURL(sURL, "_blank", 0, oProp())
   ' print Document
   oNewDoc.print(oProp())
   ' close Document
   oNewDoc.close(-1)
   
end sub


But I got an error with "oNewDoc.close(-1)". Why does ist happen?

Can I Load the JPG-File invisible?

Thank you very much again.

Regards


Simon
Back to top
DannyB
Moderator
Moderator


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

PostPosted: Mon Nov 03, 2003 10:26 am    Post subject: Reply with quote

You can load the document invisible. That is, you can open a document in OOo and have NOTHING appear on the screen. You can then manipulate the document, alter it, print it, save it, etc. Nothing visible on screen.

Pass a PropertyValue to the loadComponentFromURL. Use the "Hidden" property with the value True. If you do this, and if you leave the document open, then it is an invisible open document tying up resources such a memory.

Instead of close( -1 ) try close( True ). In OOo Basic, use the constants True and False for boolean values.

The close method is documented to take a boolean.

http://api.openoffice.org/docs/common/ref/com/sun/star/util/XCloseable.html#close

http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.htm#1+1+5+2+2+How+to+Trigger+Closing

http://api.openoffice.org/docs/DevelopersGuide/OfficeDev/OfficeDev.htm#1+1+5+2+3+XCloseable

Hope this helps.
_________________
Want to make OOo Drawings like the colored flower design to the left?
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