分享

Converting Visio files to .eps for embedding in LaTeX

 billdoors 2006-12-22

Converting Visio files to .eps for embedding in LaTeX

See below for other correspondents‘ ideas!

Anyone who has used Visio will know that the EPS (Encapsulated Postscript) export facility is broken in many ways. In the older versions, the image would very often come out completely black, and even when this is corrected, the image often had pieces missing, or was just plain wrong, and the file was not viewable with GhostScript.

With the later versions of Visio (I use Visio Professional 2002 now), it seems that setting the "Include AI format" checkbox (include Adobe Illustrator code) allows direct saving of .eps files that LyX and LaTeX can read most of the time. The files have errors (e.g. "The number of Begin and End comments do not match"), but (at least) that error doesn‘t usually appear to be fatal. You may need the latest .eps viewing tools, e.g. gsview32.exe version 4.0 or later.

However, I found that using "save as .eps", curved lines still come out awful, and others have reported problems with fonts and rotated text. Also, sometimes there are fatal errors, such as "unrecoverable error: undefined in XR". (That one I fixed by searching for the one occurrence of XR, commented out the line, and the error went away!") Doug Kaye suggested to save the file to Acrobat Distiller, then save as EPS. Well, I found that this gave errors (this is likely because I use a Windows server, and don‘t have permissions to the temporary files it seems to use), but I was able to use another facility to save the file as PDF (it emails me with a place to download the PDF from). I then use Adobe Acrobat (note: not the free AcroRead) to save the .pdf as .eps. This works, but you need to crop the page (you could use "eliminate whitespace" in Acrobat, but sometimes it shaves off a little too much. In this case, use something like GSview to crop it, manually if needed.) 

Doug recently came back with another suggestion (thanks again, Doug!):

I just discovered that when printing to Acrobat Distiller in order to make a PDF (the trick I‘ve been using), Visio 2002 Professional can‘t handle rotated text. The resulting PDF is a mess. I‘ve found another workaround, however:

1. In Visio, Save As... a Windows MetaFile

2. Import the MetaFile into a program that can handle it, such as Adobe InDesign or PageMaker.

3. Save as (or export to) a PDF.

4. Use Acrobat (not Acrobat Reader) to export as an EPS.

5. Use GSView to clean-up the bounding box (although Acrobat can do this too, just not as accurately).

If all of the above fails for you, I have reproduced my original solution to this problem. See also the end of this page for more correspondents‘ suggestions.


I find that when editing at home using LyX for Cygwin, the least painless way is to not use .eps files at all, but instead to use .pdf files. I print to a postscript file using the distiller, and include the .pdf file directly into the LyX document. This works fine, except that there is no bounding box. I add a bounding box manually using LyX‘s "clip to bounding box" option. The preview updates immediately, allowing a sort of trial and error approach. Hopefully, the size of the figure won‘t change very often, so you don‘t have to do this step very often.

This solution would not be suitable for LaTeX, only LyX. Also, it doesn‘t seem to be possible for GSview32 to convert the resultant .pdf file to a .eps either; a shame. However, ImageMagick does a great job (see notes from a correspondant below).

Since I tried that, I‘ve found some versions of LyX don‘t convert from PDF very well at all, and when you export to LaTeX, it tries to overwrite any existing .eps files in your image directory. For these reasons, I‘ve switched to exporting to .pdf using the Adobe distiller, then converting to .eps with ImageMagick. This actually saves some time, as otherwise you have to do the bounding box by hand, and also the LaTeX subsystem converts from pdf to eps for you every time you view the output, and throws away the results. If you have Lyx installed, you probably already have ImageMagick installed as well.


From Igor Dotlic:

I tried almost all approaches described at your site. However, neither of them provided good results. So I experimented a little, and here is what I came up with:

1. Add a box to your Visio drawing and send it to back. Otherwise, LaTeX won‘t be able to know size of your drawing and it will come up ugly. If you don‘t want for box to be visible, simply use white line color.
2. Group all: Ctrl-A Ctrl-G
3. Save it as wmf or emf
4. Import in Open Office Draw
5. Select your drawing - otherwise whole page will be exported and we don‘t want that.
6. Export to eps - all possible export options worked fine for me. -Done

I‘ve found no trouble till now in this method. Exported graphic is in vector format and can be resized in LaTex. I use TeXnicCenter as LaTeX editor and MiKTeX as compiler if it has any meaning.

I hope this will help someone.



From Tim West:
export as WMF from Visio, then use wmf2eps (http://www.wmf2eps./) to convert to EPS. (Many Linux and Unix machines have a wmf2eps installed by default). Thanks, Tim, this sounds like the easiest way!

However, I‘ve found errors with the wmf2eps tool. It often seems to just drop some letters from text strings for no apparent reason. Sometimes, I‘ve been able to just add a space to the end of the string, and that has fixed it. At other times, this doesn‘t work. I‘ve eneded up importing the WMF file into the Open Office Draw package. Alas, this tool doesn‘t crop its .eps output automatically, so move the drawing to the top left hand corner and use Format Page to set the size of the drawing. Sometimes I find it easier to start a diagram in Visio, then fine tune it in Draw.


From Sabine Piana:

You can save the document in Visio as wmf file and then with the programm TpX (http://tpx./) it is possible to open that wmf file and save it as eps file. (Windows only)


From Humberto Nicolas Castejon Martinez:

To make the conversion of Visio diagrams or any other Microsoft/OLE-based diagram into EPS figures I use the OLETeX program. It is a free program that can be downloaded from www./projects/oletex. It is rather simple to install and to use. Assuming that you have this program installed, this are the steps to make the conversion:

1- Select the diagram in Visio, Powerpoint, etc
2- Copy it into the OTEditor
3- Choose "EPS properties" and select the size of the figure
4- Choose "Convert.." and that‘s it!

The generated EPS has, not only a correct bounding box, but also a correct size!

Well, one more thing. In order to determine the size I wanted for a figure, this is what I did: Create a Word document with appropriate margins, paste the diagram in that document (resize it if needed) and take a look to the desired size at "Format->Object->Size"


I found this to work as well, but you need to have an application that can copy the document to the clipboard. Do follow the instructions carefully; it works for Windows XP as well (even though the Adobe Universal Printer Driver doesn‘t mention XP on the web page at all). In particular, I made two mistakes. Firstly, I accepted too many defaults and installed a generic postcript printer driver; you want to create a printer from the supplied PPD (Postscript Printer Description) file.

Second mistake: I didn‘t realise that when in Options/Conversion Settings you select a printer driver and adjust the Properties, it throws away the changes. You need to go to the *system* Printers and Faxes control panel, select the driver in there, and make the changes he describes (in particular, you must if nothing else select EPS output in the Postscript Output Option) and make them stick. It would be nice to get the program to make those changes, but I don‘t have the time to fiddle with it.

I found that I didn‘t need to do anything to choose the figure size - that‘s pretty much the point of this program, to do that step. Otherwise, you could print to a the generic printer driver and use gsview32‘s PS to EPS option. That also works, but it‘s another step. - 25/Jan/2006 Mike Van Emmerik


The best workaround that I have found is to print to a suitable printer driver that has an EPS option, and then hack the bounding box manually. The trick is to find the right postscript printer driver; many don‘t have an EPS option, and EPS is NOT just Postscript with a special header. (See the FAQs from sites like Internet resources for Postscript & Ghostscript" for details). A good driver is available from Adobe. It is most unlikely that typical drivers (like HP laserjet drivers) will work!  The Adobe download page (at present!) is http://www.adobe.com/support/downloads/main.html; look for Printer Drivers then Macintosh or Windows as appropriate, and look for a driver with a name like Adobe Universal PostScript Windows Driver Installer 1.0.6 (for Windows 95, 98, Me, NT 4.0, and 2000) - English. As of June 2002, the direct link (for Windows) is this, but it can change very quickly.

When the printer is set up, make sure that the options are set correctly; in particular, use Settings/Printers and right click on the new printer. (These instructions are for Windows NT; it may differ for Windows 95/98/etc). Under "Document Defaults" choose the "Advanced" tab, and under "Document Options" expand "Postscript Options". Under "Postscript Output Option" select "Encapsulated Postscript (EPS)". In may as well also change some Properties (on the popup menu), "Ports" tab, and choose the "FILE:" port. In fact, this is just in case you forget to check the "print to file" option when printing; this allows you to choose the path more sensibly. Save the file as ".ps", since you still have to modify the bounding box (see below) to make a true .eps file.

When this is all set up, then you can output anything (including but not limited to Visio drawings) to an EPS file by printing to that special "printer". (Just ignore the "Save as" option in Visio).

To use the EPS file as saved above with Latex, you still need to change the bounding box of the EPS file (Visio always seems to print the whole page, so the bounding box is set to whatever page you set up in Visio). That means that diagrams will wipe out all the other text on the LaTeX page. This can be done most readily by using gsview for Windows. (Note: you also need ghostscript, fonts, and another file; read the notes on those pages carefully). It has the facility for calculating a tight bounding box and saving the file with the new bounding box (under File PS->EPS). (The file still has to be EPS suitable, so it is still important to use the right printer driver to generate good EPS).

You can also do this manually; you will find it easier if you put your diagram in the bottom left corner of the page, about a centimeter from the edges. Then just edit the EPS file; about the fifth line should read something like

%%BoundingBox: 17 22 578 820
These dimensions are in points (approx. 1/72"), and represent the x and y co-ordinates of the bottom left and top right corners of the drawing. I measure with a ruler, add 10% or so, and put in the appropriate figures in the third and fourth numbers, then use Ghostscript to check that I have not cut off too much or too little. For example, suppose the diagram is 75mm wide by 100mm high; that‘s about 3" x 4". You could start with 225 and 300 for the second and third numbers. Leave the first two numbers alone.

I should add that Visio is otherewise a very good product, and I really hope that the EPS exporting is fixed in the next version (version 5 still has the problem).

What about converting to .gif?

Later versions of Visio can save directly to .gif format. For the older versions, converting to .gif‘s (e.g. for web pages) is straightfgorward. Just use File/SaveAs and save as a .bmp file, choose 96x96 DPI, 16 colours, then use any paint program to convert from .bmp to .gif (I use progressive mode for web images, though at about 12k for a large diagram, it‘s not even necessary.)

Converting eps files for use in PowerPoint

Surprisingly, Visio is very good at reading some .eps files, and PowerPoint is very bad at displaying all .eps files. (PowerPoint seems to get the text especially bad). All Windows programs seem to cope with Windows Metafile Format (.wmf) however. So if you have some .eps files that want to embed into PowerPoint presentations, this is the best way (that I found).

Start with a blank Visio page. Use Insert / Picture / From file, to insert the .eps file. If all goes well, you can just use File / Save as, select .wmf format, and save the file. You can just press the delete key to restore the blank page, and repeat for as many .eps files as need to be converted.

Things can go wrong, however. Often, the problem is a non standard character in the .eps file. To correct these problems, you need to ungroup (control shift U) the parts of the drawing. This unleashes its own set of bugs with Visio - now some of the text may be split into pieces, often overlapping. The only way to fix this is manually. I stay in pointer mode; switching continually betweeen pointer and text mode is most vexatious. It does mean that when selecting text, it will all be selected, so you need to be careful and press the end key to add text at the end. You‘ll see what I mean when you try it. I find that if you left justify the text, it will end up in just the right position (so you may as well stretch the text box nice and large, so it won‘t overflow as you add text).

You can use the character map tool (comes with Windows; usually under Programs / Accessories / System Tools) to add any special symbols in the Windows way, which should work with other Windows programs. Before saving, group the components with control shift G; then File / Save as will save the whole drawing.

Printing via PDF

If you have the full version of acrobat (not just acroread), it has the ability to convert from PDF to EPS. You can print from Visio as PDF (I use a PDF Creator pseudo printer that emails me a URL to download the file from), open the result in Acrobat, crop the image, save as EPS, then import that into other documents. This has been known to work for importing into MS Word.
Another route: Print to pdf as above, use the Unix "pdf2ps" converter, open the result in GSView, and use the "PS->EPS" option. Check the result by loading the eps into GSView.


Another thing to try

Here is a suggestion from a correspondent.

Here‘s what I did:

In Visio (2000), Save as, and use following options:
Color Translation: Normal
Line cap: device
Background Rectangle on
Include AI 3
All other options off.

Then it writes the file, which I can‘t view with GhostView 4.2
without errors. When I looked at the PS file, I found out it forgets
to insert a header:

%%BeginResource: procset Adobe_cmykcolor 1.1 0

just above the line saying:

%%Title: (CMYK Color Operators)

When I inserted that line, I could view the file in GhostView 4.2
without problems.

I guessed the line by looking at other BeginResource lines, and from
the lines at the top:

%%DocumentSuppliedResources: procset Adobe_packedarray 2.0 0M
%%+ procset Adobe_cmykcolor 1.1 0M
%%+ procset Adobe_cshow 1.1 0M
%%+ procset Adobe_customcolor 1.0 0M


Hip-hip-hurrah for the individuals that coded the exporter, and never
bothered to check whether the output actually worked.

Regards,

Frank de Jong

Thanks, Frank!

I‘ve tried this; sometimes it works, other times not. When it doesn‘t work, I use the second printing via PDF option. Here is the sed script I used to perform the insertion automatically:

/%%Title: (CMYK Color Operators)/ {
i\
%%BeginResource: procset Adobe_cmykcolor 1.1 0
}

From another correspondent, Thomas Dellsperger:
The easiest way I have found:

  • install a HP postscript printer that comes along with Windows XP (or 2000)
  • print a postscript (.ps) file from Visio to that printer
  • use ImageMagick‘s convert program to convert to eps (command line tool, you just say: convert myfile.ps myfile.eps, windows version from http://www./www/windows.html,linux version also available, of course)

Especially fonts are very well handelded that way (had some problems when
using Adobe‘s EPS printer or exporting from Acrobat). And by the way: there
is no hassle with the bounding box because Imagemagick automatically adjusts
it to fit the eps-image.


From Michael J. Hyatt:

My solution requires a PC (I‘m running Win 2000) and a Mac (OS 9.2.2),
as well as a bunch of expensive DTP software. I received a gaggle of Visio files,
which I needed to import in EPS format into FrameMaker documents
(Mac format). The procedure:

In Windows:
1. Save Visio file as WMF.
2. Import WMF file into FrameMaker (6.0 in this case) or other app with a
save-as-PDF option. (WMF opened in FrameMaker on Mac is not a pretty sight.)
3. Save as PDF.

In Mac OS:
4. Open PDF in Acrobat (5.0 in this case). (Not really necessary, but I
convert to Mac format out of habit.)
5. Save as Mac-format PDF.
6. Open PDF in Illustrator (10).
7. Save as Mac-format EPS with following options selected:
-- Version 10 (other versions no doubt work as well)
-- Mac 8-bit Color
-- Include Doc Thumbnails
-- Include Doc Fonts
-- CMYK PostScript
-- PostScript Level 2
8. Import into FrameMaker (5.5.6).

The resulting image in FrameMaker in Mac OS is identical in all respects
(lines, geometric shapes, shading, font sizes in general) to the original
Visio diagram in Windows. The only apparent differences are that circles are
not quite as perfect as in Visio, and font point sizes are smaller by a
microscopic difference but still visually the same. There is the normal
cross-platform font substitution (Arial to Helvetica, but Helvetica is
desired, anyhow).


Vehemann Ferenc reports that exporting the drawing to wmf in Visio and then opening it in Windows Illustrator works pretty well. So you don‘t need a Mac for the above solution if you have Illustrator for Windows. Thanks!


From Daniel Klose:

Here is my way, which has been done with free tools exclusivly, it might help other people too:

-Get a printing tool that creates pdf files(e.g. pdf995)
        http://www. (freeware/adware)
-After installing it, choose that new printer (pdf995) to create a pdf file from your image (or whatever)
   (Make sure that you just have ONE page!)
-After, use ghostview to convert the pdf file to a eps file
        -Open the pdf file with ghostview
        -Go to file/convert, and choose epswriter as the device
        -The boundary box has been fixed automatically
-Now you should able to include that newly created eps file into latex

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多