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

macro import html screws up images
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
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Tue May 25, 2004 6:32 am    Post subject: macro import html screws up images Reply with quote

Hi.
I have been playing around with the html import in the Writer, with a macro in Open Office. There occurs however a strange thing. For images which only have a height or width defined, but not both in the HTML page, the macro will resize the pictures, and will not scale correctly them in the resuling Open Office Text Document.
I use the "HTML (StarWriter)" filter at the import of an HTML page.

If I try to import the HTML page manually in Open Office and save it as a Open Office Text Document, all images have the correct size and scale.
Have I forgotten to include a filter option with the HTML filter?
I use the following macro code, found in this forum:
Code:

Sub ConvertHTMLToSXW( )
   cSourceDoc = "C:\2004-05-06-word-test\2004-05-06-word-test2.htm"

   ' Open Html as a Writer document
   oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0,_
         Array(_
             MakePropertyValue( "FilterName", "HTML (StarWriter)" ),_
          ) )


   ' Same as cSourceDoc, but different extension
   cDestDoc = Left( cSourceDoc, Len( cSourceDoc ) - 4 ) + ".sxw"
   oDoc.storeToURL( ConvertToURL( cDestDoc ), Array() )

   oDoc.close( True )
   
End Sub
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 May 25, 2004 11:30 am    Post subject: Reply with quote

I recommend that you manually import the document and then use getArgs() on the document model to see exactly which import filter was used. Be certain to use that same import filter. This is the first step that I take when I need to solve such problems.
_________________
--
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
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Tue May 25, 2004 11:57 pm    Post subject: Reply with quote

On your advice I used getArgs to see which filter was used when I manually worked with Open Office. Indeed another filter "HTML" was used. But now I want to save this file as an Open Office Text Document. So I looked up which filter to use, and ended up with "StarOffice XML (Writer)". However I can't use this in a macro in combination with storeToURL(). It will throw an IOException.
When I manually export the HTML page to an Open Office Text Document everything goes fine. When I use getArgs on the newly created page it states that the filter name is "StarOffice XML (Writer)".
So what am I doing wrong in the macro?
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 May 26, 2004 10:31 am    Post subject: Reply with quote

The following code works for me:

Code:
  Dim oImportArgs(0) As New com.sun.star.beans.PropertyValue
  Dim sURL As String
  Dim oDoc
  oImportArgs(0).Name = "FilterName"
  oImportArgs(0).Value = "HTML (StarWriter)"
  sURL = "file:///andrew0/home/andy/andy.html"
  oDoc = StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, oImportArgs())
  If IsNull(oDoc) Then
    Print "Unable to load the file " & sURL
    Exit Sub
  End If

  Dim oExportArgs(0) as new com.sun.star.beans.PropertyValue
  oExportArgs(0).Name = "FilterName"
  oExportArgs(0).Value = "StarOffice XML (Writer)"
  oDoc.storeToURL("file:///andrew0/home/andy/andy.sxw",oExportArgs())

_________________
--
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
Guest






PostPosted: Wed May 26, 2004 12:35 pm    Post subject: Reply with quote

I'll give you an example of the HTML page:
Code:

<html>
<body>
<IMG src="distress_sigs.jpg" width=350 align=top>
</body>
</html>


Distress.jpg is an local image with width 350 and height 530. Notice that in the above code only the width is entered.

If I run the following OOBasic macro:
Code:

Sub ConvertHTMLToSXW( )
   cSourceDoc = "C:\test.htm"
   ' Open Html as a Writer document
   oDoc = StarDesktop.loadComponentFromURL( ConvertToURL( cSourceDoc ), "_blank", 0,_
         Array(_
             MakePropertyValue( "FilterName", "HTML (StarWriter)" ),_
          ) )


   ' Same as cSourceDoc, but different extension
   cDestDoc = Left( cSourceDoc, Len( cSourceDoc ) - 4 ) + ".sxw"
   oDoc.storeToURL( ConvertToURL( cDestDoc ), Array() )

   oDoc.close( True )
   
End Sub

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


The resulting Staroffice document contains a stretched image with wrong scaling and wrong size. I can provide you with the image if you want.
Can you let me know if my example works fine with you?
Back to top
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Wed May 26, 2004 12:37 pm    Post subject: Reply with quote

That was me, forgetting to log in. Comment on my post: "Distress.jpg" should be "distress_sigs.jpg".
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Thu May 27, 2004 12:21 pm    Post subject: Reply with quote

My reply made no comment on the correctness of the output, it was to show some code that read and wrote data. You indicated that your code threw an IO exception.
_________________
--
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
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Thu May 27, 2004 12:46 pm    Post subject: Reply with quote

pitonyak wrote:
You indicated that your code threw an IO exception.

It will still throw an IO Exception when I use "HTML" as filtername instead of "HTML (StarWriter)" and I use storeToURL() with filtername "StarOffice XML (Writer)".
So with "HTML (StarWriter)" the output is not correct, and with "HTML" I get an IO exception. I'm a bit lost now, in how I can get a Text Document with correct scaled+sized images when I import a HTML page.......
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Thu May 27, 2004 5:50 pm    Post subject: Reply with quote

I have duplicated your results. In other words, it looks like a file opened as HTML can NOT be saved in that particular format. There are some formats that it does support, but not as a regular office document.

I also duplicated what happens when a graphic changes. It not only changes the size of the graphic, but the ratio as well.

If the document is opened as "HTML (StarWriter)" , are the images OK in the HTML file but wrong in the sxw file? This is what I see. Either way, you can always load the document in the way that works, and then traverse the document and obtain each graphics object and then resize the graphic in the newly exported document. Not nice, but it should work.
_________________
--
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
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Thu May 27, 2004 10:59 pm    Post subject: Reply with quote

Indeed the images are wrong in the sxw file. I will try your advice on resizing the graphic objects. Thanks for your help.
Back to top
View user's profile Send private message
pitonyak
Administrator
Administrator


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

PostPosted: Fri May 28, 2004 11:25 am    Post subject: Reply with quote

I have some code at home that is written in Java I think , that will go through a document, find every image, and then export it. If you would like to see a copy of it, let me know. I had only provided a hint on how to do it so I was sent a copy.

If you want a copy, email me at my home email address....

andrew _at_ pitonyak.org

and I will send it to you.
_________________
--
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
Guest






PostPosted: Sun May 30, 2004 9:33 pm    Post subject: Reply with quote

To pitonyak
I am intersting in the code you wrote in java . Can you show it in the forum.
Thank you.
Back to top
DannyB
Moderator
Moderator


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

PostPosted: Mon May 31, 2004 8:18 am    Post subject: Reply with quote

pitonyak wrote:
I have duplicated your results. In other words, it looks like a file opened as HTML can NOT be saved in that particular format. There are some formats that it does support, but not as a regular office document.


In my experience, opening an HTML file without specifying an import filter name results in the html file being opened as a Web document, rather than as a Writer document.

Web documents have a limited number of export options.

Writer documents have a rich set of export options.

The solution I use is to open the HTML document, specifying the filter name that opens html docs into Writer. Then you can export using any of Writer's export filters.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
johnny7
General User
General User


Joined: 21 May 2004
Posts: 10

PostPosted: Wed Jun 02, 2004 12:36 am    Post subject: Reply with quote

Hi DannyB.
I also read your comment on the filter name somewhere else in the forum.
What I don't understand is, that it is manually possible in Open Office to open a Web document, not in Writer, and export this to an Open Office Textdocument, but in a macro this task can't be accomplished. It seems I have to revert to opening the Web document in Writer, which leads to the problems, already mentioned by me in this topic.
Shouldn't a macro be able to do the same things as what is done when I manually use Open Office?
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 02, 2004 7:15 am    Post subject: Reply with quote

johnny7 wrote:
Shouldn't a macro be able to do the same things as what is done when I manually use Open Office?


In principle, yes it should be possible to do anything from a macro that can be done manually.

Especially in regard to import/export. It should just be a matter of finding the correct filters to use.

I do know that HTML can be opened in either Web or Writer mode. Writer offers more export choices. If you don't specify the html to writer import filter, then you get html opened in Web by default, which offers few export options. You seem to be saying that opening html in Writer screws up the html somehow?

There are some things where OOo still does not offer either API or Dispatcher support for certian operations. For example, it is impossible, as far as I know, to create a drawing with 3D objects on it, and manipulate the scene lighting, textures, etc. from a macro.
_________________
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
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