Save as HTML

Started by mem007, September 25, 2014, 03:11:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mem007

Hi!  This is markem at work.  :-)

Ok - First is I am using Visio 2003.  Second is - I know you can save a diagram as HTML via the SaveAs... option.

What I want to do is to generate the HTML myself.  Why?  Because when you save your drawing as HTML Visio creates a flat image out of what you have and it stores that as an image.  That is not what I want to do.  I want to generate the HTML to absolutely position my images.  This is easily done via HTML by doing the following:

<img src="<Source>" style="position:absolute;top:##px;left:##px;z-index:##" />

Where "position:absolute" means just that - to position the image on the page using absolute positioning.
Where "top:##px" means how far down from the top to place the image in pixels.
Where "left:##px" means how far across from the left to place the image in pixels.
Where "z-index:##" means where on the Z-axis to place the image.  This is the same as what layer to place the image.

So my first objective was to find a way to save each image individually.  I found this by searching through the previous postings and someone named AL had posted a script to go through and individually save each image.  Which is the first step.  :-)

What I am wanting to do now is to save the HTML code into a file (along with a standard HTML header and footer).  I am currently at work and can not work on this here (because I'm doing this so I can import the entire page layout into Fireworks for my D&D game).  I am assuming I can get the name of the image from the name field and the width, height, top, and left also from the shape sheet.  (I haven't found how to tell what layer the image is on.)  So really what I am wondering about is how to write the HTML code out to a file.  Am I making a mountain out of a mole hill here?  Is it as easy as just doing the VBA open-write-close stuff?  Or is there some special VBA code I need to use to do this?  Any simple example code?  Especially on how to get which layer the shapes are on and do I have to generate my own layer numbers?  (Since layers in Visio have names like "ground", "1st floor", etc....)

Thanks ahead of time and I promise not to go ballistic when Yacine posts a very simple solution I should have seen to begin with.  :-)


mem007

Ok - found this on layers.  I can now get the layer names and know how many there are.

http://visguy.com/vgforum/index.php?topic=212.msg886#msg886

Still looking for how to write to a file so I know I'm doing it write....er right.  :-)

Paul Herber

I think that what you are wanting is to save each individual shape as a separate image, then locate each image using HTML. Is this correct?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

mem007

Ok - found how to write text info out:

http://visguy.com/vgforum/index.php?topic=2677.msg11800#msg11800

Took a while to find everything. E-mailed to my home e-mail account.

Paul:

Yes - kind of.

What I am wanting to do is this:

<HTML>
<HEAD>
<TITLE>Image</TITLE>
<BASE href="file:///c|a/b/c" />  <!-- Tells where the images are located -->
</HEAD>
<BODY>
<img src="file_001.png" width="##px" height="##px" style="position:absolute;top:##px;left##px;z-index:##" />
<!--Repeat the above once per image -->
</BODY>
</HTML>

The program is to:

1)Cycle through each page in the document
1a)Open a new web page (using a simple name like PAGE_####.htm) and generate the header part.  Do this for each page in the document.
2)Determine the layers (if any) and equate an ID number to each layer.  (It turns out that the layers all have an ID number already in the layers array.)
3)Extract the information about each shape on the web page.
4)Using the X. Y, Width, Height, Layer, and Name fields - generate the IMG command for that image.
5) Write out each image's command
5a)Save the shape out to a PNG file (with transparency, etc...).
6)Finish the HTML informaton, close that file and open the next one.
7)Finish up and let me know it is through.

The example script I found saves everything as a 2"x2" shape.  I'd want to change this to be the shape's width and height which is stored in the shapesheet.

TIA! :-)

Paul Herber

Things might not be as simple as that.
Where are you getting the images from?
Each shape's location is not just its X,Y coordinates. You also have to take into account the shape's LocPinX and LocPinY. What about grouped shapes? What about shapes where the text is located outside the shape area?
Overlapping shapes? What about shape transparency?
Just for starters.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

mem007

I will try to remember to post my script once I have finished it.  Thanks to AL, Paul, et al.  Hopefully this will help someone else be able to export their layouts into an HTML version that isn't just one large image.  In this way other programs (such as Microsoft Word, AbiWord, etc...) can then load in the HTML web page and each image will still be individuals so they can each be moved around if need be.

Why am I doing this now?  I recently bought a WinBook(R) at MicroCenter here in Houston, Texas.  The WinBook runs Windows 8.1.  I did some research on changing it back to Windows XP but have as of yet to find the drivers I would need to do so.  As such I can't install my Windows Office 2003 onto the tablet.  This means that all of my D&D stuff I have developed using Visio 2003 has to be converted to something else.  I already own the Adobe Master Suite CS3 which has Fireworks in it.  Fireworks does both vector and bitmapped images so ideally I'd like to just move everything to Fireworks (which will install and run on the WinBook).  Unfortunately, in CS3 Adobe had not created a way to export Visio layouts to Fireworks but Fireworks will read web pages.  All of the other formats (ie: SVG, EPS, EMF, PDF, and even PSD) take your drawing and create a single image from it and then export that to the selected file.  Under the XML stuff - Visio WILL export to individual images but nothing else will read those generated files.  (I have tried Firefox, Opera, Chrome, IE, and several other programs that read XML files - but no go.  Only Visio 2003 will read a Visio 2003 XML file.  Newer versions of Visio probably will read such files also but nothing else seems to be able to do so.) So all of the different output formats (under Visio 2003) will only generate a single image or is unreadable otherwise.  I want each of the individual images to be separate so when it is read in by some other program (ie: Firefox, Fireworks, etc...) the absolute position is kept so that not only do I get the images - but I get the same exact image as I had in Visio.

I may also write an XML export script to do the same thing as the HTML output simply because Visio 2003 doesn't do that correctly for unknown reasons.  XML would also be a lot more flexible than the HTML code by itself.

mem007

Paul:

All shapes are going to be ungrouped.  I will make sure of that before I start - but I could put something in to the code to ungroup everything.  Correct?  :-)

All images are IN the document.  I imported a lot of images via the Image->Import part.  One of the problems with my documents.  Lots of bit mapped images.

Yeah, I saw those in the shape sheet but I was going to try without that first and then modify as needed.

Don't have any images with the text outside of the shape area.  In the cases where I want that I create a text object and then place the text object next to or on top of the object.  I know - using two things to do what one can do but to me it is more flexible to have the two separate objects and then just group them together.  (And thus the ungrouping before doing anything.)

I do have some sticky notes on some of the graphics (like what someone did at some location so I know to take that something into account).  I figure I will work on those after getting this to work.

There are a lot of overlapping shapes.  However, the overlapping shapes are usually for such things as forests where the tree images overlap each other.  Since I use the Move Forwards and Move Backwards to adjust where the images are (so they look nice) - I can adjust them afterwards.  I'm mainly trying to get something that looks similar to what I have - if not exact.  :-)  Transparency is handled by the first routine I found from AL.  The transparency color value is an offset color.  So I haven't had the time yet to type the program up and/or use it.  Once I have I might adjust the transparency color but each of the images has transparency and I realize I might have to work at getting a standardized transparency color.

I'm hopeful though that with the scripts I've found that I should be able to get something up and running and then I can work from there.  :-)

Paul Herber

Quote from: mem007 on September 25, 2014, 04:32:31 PM
All shapes are going to be ungrouped.  I will make sure of that before I start - but I could put something in to the code to ungroup everything.  Correct?  :-)

No, ungrouping can/will break shapes. Never do this.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

mem007

Paul:

QuoteNo, ungrouping can/will break shapes. Never do this.

Er.....I group/ungroup images all of the time and have never had any problems.  What do you mean it will break the shapes?  Because this is news to me.  :-)  I group->save, ungroup->save, move things around->save and never have any problems.  I do this because people are playing in my game and I move their images around, add such things as swords, bows&arrows, helmets, etc..., then later on I remove/replace weapons, clothes, armor, etc... and resave without a problem.  Shape sheets still show all of the information.

So what are you talking about?  Remember I'm using Visio 2003.  So if there has been some kind of a change in later versions it might not affect what I am doing.  Let me know.  Thanks!  :-)

Paul Herber

If you've grouped the shapes yourself, that's ok!
However, problems can still arise when the shapes within the group are located relative to the group shape. When ungrouped the sub-shapes can just fly apart, oftem to location 0,0 on the page.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

mem007

Paul:

Ok - all of my shapes I import, group, and ungroup by hand.  So none of them will (or should) go flying apart.  They never have so far but then I don't try to do really complicated things.  I just put things together so everyone can see where they are in the game.