This is Google's cache of http://www.thinkingms.com/pensieve/2007/02/15/UsingVisioDiagramsInLatex.aspx. It is a snapshot of the page as it appeared on 13 Jul 2008 09:57:18 GMT. The current page could have changed in the meantime. Learn more »

Text-only version
These search terms are highlighted: visio pdf bounding box latex  
 Thursday, 15 February 2007

This shows you how you can use Microsoft Visio diagrams in LateX as vector diagrams. One may always save diagrams as JPG or PNG and use them in Latex. But to keep them freely resizable takes a bit more of work.

You need to do this in 2 steps:

1) Save as PDF: Visio doesn't directly let you save images as PDF. Instead one may use a PDF printer driver such as PrimoPDF. This is a free printer driver that one may install on Windows and it works rather well. Here is a the URL:

http://www.primopdf.com/

Once PrimoPDF is installed, you can selected a diagram in your Visio document and hit CTRL+P to print it. When the print dialog appears make sure that the current selection is only printed and that it prints to PrimoPDF. Once hit OK to print, PrimoPDF will pop up a dialog box asking for the filename of the pdf to be saved. Hence you generate a PDF from the Visio diagram.

Though this step seems a little elaborate, in practice this is only as much effort as saving an image selection to a file.

Update 

As pointed out by Pandu in the comments, you can install 2007 Microsoft Office Add-in: Microsoft Save as PDF or XPS to help create a PDF out of the visio image, instead of intalling PrimoPDF. If you go this route, you will find an expore to PDF or XPS option under your file menu and you dont have to print to a PDF driver. (This approach maybe a little more tedious that the previous because you often want to save one image on your page, the selected one - if you choose to Print, the option for "selection" in on the print dialog box; if you choose to export to pdf, the option for "selection" is in a nested dialog box. (aah, the pleasure of GUIs))

The amount of effort involved is the same and step two hold regardless of what approach you choose. Thanks Pandu!

 

2) Including in the Tex file: You may include the PDF in a Tex file using the graphicx package. There are many handy online tutorials about this package. Each image is included in the latex file use a \includegraphic statement.

The real difficulty is this: The pdf file generated has the image at some position on the page. Including the whole file includes all of the white space on the page. This messes up the pdf you generate from the latex file. There are two possible solutions:

- Use a tool to remove whitespace: pdftrimwhite or pdfcrop might work. They are bot included with MikteX. Neither however worked for me as I couldn't get them to run. They both failed to run with the error: perl script not found. Does anyone know what the matter is? I have the latest ActivePerl in my path.

- Specify a Viewport: This is what worked for me. A viewport is a specification of what region of the pdf file to display in the latex document you are creating. Most websites I found tell you that you have to guess at the viewport - here is a better way.

You can use pdf2ps (ships with MikteX) to generate a ps file. If you open the ps file in a text editor, among the first few lines, you will see a comment about the bounding box.

%%BoundingBox: 28 779 142 809

This is the  viewport information, you need on the basis on which you can type the command:

\includegraphics[viewport = 28 779 142 809]{file.pdf}

That's it. If this step seems a little tedious, here is a ruby script:

$stdin.each_line{|fn|
    fn = fn.strip
    if fn =~ /.*\.pdf/
        `pdf2ps #{fn} #{fn}.ps`
        File.new(fn + ".ps").each_line{|line|
            if /%%BoundingBox: (.*)/i =~ line
                puts "\\includegraphics[viewport = #{$1}]{#{fn}}"
                break
            end
        }
    end
}

 You may use the script as follows:

> echo file.pdf | ruby pdfimage.rb
\includegraphics[viewport = 28 779 142 809]{file.pdf}

If you use subcode, then you can abstract this whole step away into a filter and then just include pdf file directly into your latex and let it insert the viewport during compilation.

There you go. If you can help improvise on any of this, let me know.

Thursday, 15 February 2007 17:50:03 (Eastern Standard Time, UTC-05:00)  #    Comments [8]  | 
Tuesday, 20 February 2007 10:44:44 (Eastern Standard Time, UTC-05:00)
If you are using Visio 2007, you can do a Publish to PDF or XPS. You need this download:

http://www.microsoft.com/downloads/details.aspx?familyid=4D951911-3E7E-4AE6-B059-A2E79ED87041&displaylang=en

if you are using Office 2007. And no, I am not trying to sell it to you.
Tuesday, 20 February 2007 19:28:18 (Eastern Standard Time, UTC-05:00)
:) I am using Visio 2007. I actually bought a copy.
Btw, I have acess to office 2007, is it worth installing?
Wednesday, 10 October 2007 17:14:15 (Eastern Standard Time, UTC-05:00)
The following macro will export all pages of a Visio document to single PDF files with the correct bounding box using the PDF publish functionality. No additional scripts, no time consuming dialogs.

Sub ExportAllPagesFromActiveDocument()
' Summary: Export all pages from a document to PDF
' Author: Marc Schinnenburg
'
Dim currentPage As Page
Dim allPages As Pages
Dim doc As Document

Set doc = Application.ActiveDocument
Set allPages = doc.Pages

' strip .vsd from the document name
documentName = Replace(doc.Name, ".vsd", "")

For ii = 1 To allPages.Count
Set currentPage = allPages(ii)
pageName = currentPage.Name
' generate new export name: "current path" + "file name without .vsd" + "name of the page"
exportName = doc.Path + documentName + "_" + pageName

' export to png
' currentPage.Export exportName + ".png"

' resize page to get correct bounding box
currentPage.ResizeToFitContents
' export to PDF
doc.ExportAsFixedFormat visFixedFormatPDF, exportName + ".pdf", visDocExIntentPrint, visPrintFromTo, ii, ii
' undo resize since it was only needed for printing
Application.Undo

Next ii
End Sub
Marc Schinnenburg
Wednesday, 05 March 2008 12:27:03 (Eastern Standard Time, UTC-05:00)
@Marc or someone else:

Where do I run this macro?
John
Wednesday, 05 March 2008 12:56:39 (Eastern Standard Time, UTC-05:00)
I am not sure myself. Even if the macro generates a PDF with the right bounding box info, it still does not tell you how to specify it in the includegraphics latex tag (unless I am missing something).

Tuesday, 29 April 2008 04:08:49 (Eastern Standard Time, UTC-05:00)
You can find more information on how to use the marco (in an updated version) here: http://www.codestylist.org/wiki/ExportToPdf

@Roshan: I never needed to define any viewports. I guess there is no additional information needed to include the graphic, except the filename of course.
Marc Schinnenburg
Friday, 16 May 2008 08:24:27 (Eastern Standard Time, UTC-05:00)
Marc, the link you provided (http://www.codestylist.org/wiki/ExportToPdf) doesn't work for me. Can you give please the working URL? Thanks.
Monday, 19 May 2008 10:37:29 (Eastern Standard Time, UTC-05:00)
Arthur, the page was down for some days. It should be up again.
Marc Schinnenburg
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
StatCounter - Free Web Tracker and Counter