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

select graphics in text document and save in directory
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
sam2004
General User
General User


Joined: 19 Apr 2004
Posts: 23

PostPosted: Wed Jun 16, 2004 9:54 am    Post subject: select graphics in text document and save in directory Reply with quote

Hi, ich have a question. How can i select graphics in text document and then save them in a directory?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


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

PostPosted: Wed Jun 16, 2004 11:45 am    Post subject: Reply with quote

Without writing any code, and if you only have to do this for a very small number of documents, I can think of a way.

Save your Writer document into that directory as HTML. It will save all of the graphics (not necessarily in the format you want). Then delete the HTML file and keep the exported graphics.
_________________
Want to make OOo Drawings like the colored flower design to the left?
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 Jun 16, 2004 12:00 pm    Post subject: Reply with quote

DannyB,

Might it be possible to copy the text image to the clipboard, paste it into a Draw document, and then export it from there? I know that you can export it from a draw document, but I have not figured out how to do it from a Writer document.
_________________
--
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: Wed Jun 16, 2004 12:49 pm    Post subject: Reply with quote

pitonyak wrote:
Might it be possible to copy the text image to the clipboard, paste it into a Draw document, and then export it from there? I know that you can export it from a draw document, but I have not figured out how to do it from a Writer document.


I believe that would be possible. Here is a recently written example
http://www.oooforum.org/forum/viewtopic.php?p=36035#36035
that creates a Calc spreadsheet, then makes a chart of the data, then selects the chart. What I have just described, to this point, is irrelevant. Then with the chart selected, it does a Copy, create new Drawing, Paste, then Export to Jpeg. If you can select the graphic in Writer, then it should be possible to combine with code from the example I just linked.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Wed Jun 16, 2004 5:19 pm    Post subject: Reply with quote

Doing this with the GUI is very simple with the "Export" menu item and activating the "Selection" checkbox, saving it as a bmp, gif file or whatever. I wonder if this can be invoked with Starbasic, but didn't find anything yet.
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
sam2004
General User
General User


Joined: 19 Apr 2004
Posts: 23

PostPosted: Thu Jun 17, 2004 12:52 am    Post subject: select graphics in text document & save in dir w. OO-Bas Reply with quote

Hi, thanks for your answer.
sorrry, i think i didn' t write clearly. What i want to do, is, with OO Basic graphics are tol be selected in text document and saved in a directory. Do any one know the code for it?
I am grateful for each help
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


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

PostPosted: Thu Jun 17, 2004 10:12 am    Post subject: Re: select graphics in text document & save in dir w. OO Reply with quote

sam2004 wrote:
Hi, thanks for your answer.
sorrry, i think i didn' t write clearly. What i want to do, is, with OO Basic graphics are tol be selected in text document and saved in a directory. Do any one know the code for it?
I am grateful for each help


I am not clear on what you want to do. I can interpret what you said in two different ways....
1. You want macro to open Writer document, discover all graphics in the document, and export each one.
2. You want user to open Writer document, work with it. User selects a graphic. User invokes a macro that exports the selected graphic.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
sam2004
General User
General User


Joined: 19 Apr 2004
Posts: 23

PostPosted: Fri Jun 18, 2004 12:51 am    Post subject: select graphics in text document & save in dir w. macro Reply with quote

How can you do in order to get the graphics in a text document into a entire directory, eg. in c:\objects, or copy the graphics from directory "Pictures" (Writer save the graphics always in this directory) to dir. c:\objects and rename the graphics (because the graphics has following form 100000000000012000000108AB886992.gif, so you don't know whether this is a graphic1 or 2).
I want do it with macro, is it possible?
I hope, you can understand me.
Back to top
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Sun Jun 20, 2004 5:05 pm    Post subject: Reply with quote

Hi Sam, you might wanna find the following thread useful:
http://www.oooforum.org/forum/viewtopic.php?t=6769

If you are not able to get it working then reply and I or others will then take a look at it.

Hope that helps.
Christian
_________________
- Knowledge is Power -
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Mon Jun 21, 2004 9:00 am    Post subject: Reply with quote

I think I do have the same problem. Let me try to explain it in more detail:

THE SITUATION: I'm working on an export-mechanism to save a Writer document to a xml-based structure. Therefore, I have to scan the whole document to read it's structure, text and graphics. Concerning the graphics: they have to be stored into a new folder in the filesystem in the same format, as they have been integrated in the document (they are not linked but inserted).

The document is parsed by an enumeration object. The paragraphs of the document are retrieved with the following code:
Code:
sub ExportDoc
Dim oThisDoc as Object
Dim oEnum as Object
Dim oEnumObj as Object

  oThisDoc = ThisComponent()
  oEnum = oThisDoc.Text.createEnumeration
  while oEnum.hasMoreElements())
    oEnumObj = oEnum.nextElement()
    If oEnumObj.supportsService("com.sun.star.text.Paragraph") Then
      ExportParagraph(oEnumObj)
    end if
  wend
end sub

sub ExportParagraph(oObj as Object)
' Export the text (has been done with the oObj.GetString method)
' Export graphic(s) if there are in this paragraph (has to be done)
end sub

THE QUESTIONS: How can I "find" one or more graphics within a paragraph by code? How can I export these graphics in their original format (jpg, gif, png)? I studied this thread an the threads you mentioned here. Unfortunately, it seams not exactly to be the solution for the described problem.

Any help would be very appreciated,

Regards, Harry
Back to top
pitonyak
Administrator
Administrator


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

PostPosted: Mon Jun 21, 2004 10:50 am    Post subject: Reply with quote

According to the Developer's Guide,
Quote:
The XContentEnumerationAccess of the paragraph lists the shape objects anchored at the paragraph while the XContentEnumerationAccess lists the shape objects anchored at a character or as a character.

I tested this with the following code, and it does indeed enumerate the graphics objects.
Code:
sub ExportParagraph(oObj as Object)
  Dim oEnum
  Dim oEnumObj

  oEnum = oObj.createEnumeration()
  Do While oEnum.hasMoreElements()
    oEnumObj = oEnum.nextElement()

    If oEnumObj.TextPortionType = "Text" Then
      REM This is a simply text object!
      'MsgBox oEnumObj.TextPortionType & " : " & CHR$(10) & oEnumObj.getString()
    ElseIf oEnumObj.TextPortionType = "Frame" Then
      Dim oEnum_2
      Dim oGraphicObject
      REM Use an empty string to enumerate ALL content
      oEnum_2 = oEnumObj.createContentEnumeration("com.sun.star.text.TextGraphicObject")
      Do While oEnum_2.hasMoreElements()
        oGraphicObject = oEnum_2.nextElement()
      Loop
    End If
  Loop
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
harrybo
Power User
Power User


Joined: 27 Apr 2004
Posts: 75
Location: Germany

PostPosted: Mon Jun 21, 2004 4:02 pm    Post subject: Reply with quote

Thank you, pitonyak, for your prompt answer. I checked your code and it does work properly when the graphics are anchored at a character (took me some time, to discover this). If a graphic is anchored at a paragraph, the graphic will not be found.

The Developers Guide (http://api.openoffice.org/docs/DevelopersGuide/Text/Text.htm#1+3+1+2+Iterating+over+Text) does not really explain this point well: The TextPortionType "Frame" is not listed and there must be something wrong in the sentence you quoted: both are "XContentEnumerationAccess", so why "while"?

Remaining questions:

1.) How can I Iterate through a l l graphics within a paragraph, no matter where the graphics are anchored, what means: how can I reflect the different anchor types, to find all graphics/shapes?

2.) How can I then export these graphis with the format, they have had when they where inserted (see above)?

Thank you

Regards, Harry
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pitonyak
Administrator
Administrator


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

PostPosted: Mon Jun 21, 2004 8:15 pm    Post subject: Reply with quote

The code that I already provided should find a graphcis that is set As a character, and To a character. I thought that a graphic that was anchored to a paragraph was enumerated with the paragraph. I will have to think about this for a bit.....
_________________
--
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
sam2004
General User
General User


Joined: 19 Apr 2004
Posts: 23

PostPosted: Tue Jun 22, 2004 4:52 am    Post subject: Reply with quote

Hi Christian, thank you for your reply. The code under the links
http://www.oooforum.org/forum/viewtopic.php?t=6769
ist for export graphic from draw document, i want export graphic from writer document, whereas the graphics stay unchanged. Any idea, how it could be done?
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Tue Jun 22, 2004 12:35 pm    Post subject: Reply with quote

The Developer's Guide states the following:
Quote:
The text portion enumeration of a paragraph does not supply contents which do belong to the paragraph, but do not fuse together with the text flow. These could be text frames, graphic objects, embedded objects or drawing shapes anchored at the paragraph, characters or as character. The TextPortionType "TextContent" indicate if there is a content anchored at a character or as a character. If you have a TextContent portion type, you know that there are shape objects anchored at a character or as a character.

This last group of data contained in a text, Paragraphs and TextPortions in writer support the interface com.sun.star.container.XContentEnumerationAccess. This interface tells which text contents besides the text flow contents there are and supplies them as an com.sun.star.container.XEnumeration:

sequence< string > getAvailableServiceNames()

com::sun::star::container::XEnumeration createContentEnumeration( [in] string aServiceName)

The XContentEnumerationAccess of the paragraph lists the shape objects anchored at the paragraph while the XContentEnumerationAccess lists the shape objects anchored at a character or as a character.

This tells me that I should be able to call createContentEnumeration() from a paragraph object to enumerate the graphics objects that are anchored to the paragraph. At least, I assumed it to be true. So, I checked the available service names and then it all became more clear!
Code:
sub ExportDoc
  Dim oThisDoc as Object
  Dim oEnum as Object
  Dim oEnumObj as Object

  oThisDoc = ThisComponent()
  oEnum = oThisDoc.Text.createEnumeration
  while oEnum.hasMoreElements()
    oEnumObj = oEnum.nextElement()
    If oEnumObj.supportsService("com.sun.star.text.Paragraph") Then
      ExportParagraph(oEnumObj)
      Dim oEnum_2
      Dim oGraphicObject
      'MsgBox Join(oEnumObj.getAvailableServiceNames(), CHR$(10)
     
      REM Use an empty string to enumerate ALL content causes a runtime error!
      oEnum_2 = oEnumObj.createContentEnumeration("com.sun.star.text.TextContent")
      Do While oEnum_2.hasMoreElements()
        oGraphicObject = oEnum_2.nextElement()
        If oGraphicObject.supportsService("com.sun.star.text.TextGraphicObject") Then
          Print "Found a graphic object anchored to a Paragraph"
        End If
      Loop
    End If
  wend
end sub

sub ExportParagraph(oObj as Object)
  Dim oEnum
  Dim oEnumObj

  oEnum = oObj.createEnumeration()
  Do While oEnum.hasMoreElements()
    oEnumObj = oEnum.nextElement()

    If oEnumObj.TextPortionType = "Text" Then
      REM This is a simply text object!
      'MsgBox oEnumObj.TextPortionType & " : " & CHR$(10) & oEnumObj.getString()
    ElseIf oEnumObj.TextPortionType = "Frame" Then
      Dim oEnum_2
      Dim oGraphicObject
      REM Use an empty string to enumerate ALL content
      oEnum_2 = oEnumObj.createContentEnumeration("com.sun.star.text.TextGraphicObject")
      Do While oEnum_2.hasMoreElements()
        oGraphicObject = oEnum_2.nextElement()
        If oGraphicObject.supportsService("com.sun.star.text.TextGraphicObject") Then
          Print "Found a graphic object anchored to or as a character"
        End If
      Loop
    End If
  Loop
End Sub

Wow, what a ride!
_________________
--
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
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
Goto page 1, 2  Next
Page 1 of 2

 
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