Microsoft® Visio Formats Conversion Via Java

Convert MS Visio Diagrams to HTML, PDF and Images including JPG, BMP, PNG, TIFF to build cross-platform Java applications.

 

For any Microsoft Visio formats rendering solution such as designing flowcharts and business flow diagrams etc Java Visio API facilitates all the complex drawings in an easy way. Load source file using Diagram class and call the save method with appropriate parameters.

Inter Conversion Visio Files

Programmers can easily convert VSDX, VSX, VTX, VDX, VSSX, VSTX, VSDM, VSSM, VSTM formats as well as loads VDW, VSD, VSS, VST and renders to PDF, HTML and Images. Considering the scenario of VSDX to VDX, process is, load the source VSDX file using diagram class and call the save method by providing output file and SaveFileFormat .VDX as parameters.

Java Code for VSDX to VDX Conversion
// Load the VSDX in an object of Diagram
Diagram visio = new Diagram("template.vsdx");
// save VSDX as VDX
visio.save("output.vdx", SaveFileFormat.VDX);
 

Visio to Images Conversion

For generic conversion, process of converting visio files to images is same. Just load the file via Diagram class and call the save method with output file and SaveFileFormat output parameters. And whenever there is need to define specific options, developers can use ImageSaveOptions class while converting diagram pages to images and SVGSaveOptions for SVG conversion.

Java Code to Convert Visio to Image Formats
Diagram vsdxtoImages = new Diagram("sourceDocument.vsdx");
ImageSaveOptions ImgOptions = new ImageSaveOptions(SaveFileFormat.JPEG);
// specify the quality level to use during compositing.
ImgOptions.setCompositingQuality(CompositingQuality.HIGH_QUALITY);
//The default value is 0.5. The value must be in the range between 0 and 1.
ImgOptions.setImageBrightness(1f);
ImgOptions.setDefaultFont("MS Gothic");
// sets the number of pages to render in image.
ImgOptions.setPageCount(2);
// sets the 0-based index of the first page to render. Default is 0.
ImgOptions.setPageIndex(0);
// set page size
PageSize pgSize = new PageSize(PaperSizeFormat.A_1);
ImgOptions.setPageSize(pgSize);
// discard saving background pages of the Visio diagram
ImgOptions.setSaveForegroundPagesOnly(true);
// sets the color mode for the generated images.
ImgOptions.setImageColorMode(ImageColorMode.BLACK_AND_WHITE);
// the default value is 0.5. The value must be in the range between 0 and 1.
ImgOptions.setImageContrast(1f);
// this property has effect only when saving to raster image formats.
ImgOptions.setInterpolationMode(InterpolationMode.NEAREST_NEIGHBOR);
// the value may vary from 0 to 100 where 0 means worst quality,
ImgOptions.setJpegQuality(100);
// set a value specifying how pixels are offset during rendering.
ImgOptions.setPixelOffsetMode(PixelOffsetMode.HIGH_SPEED);
// sets the resolution for the generated images, in dots per inch. The default value is 96.
ImgOptions.setResolution(2f);
// the default value is 1.0. The value must be greater than 0.
ImgOptions.setScale(1f);
// specify whether smoothing (antialiasing) is applied to lines
// and curves and the edges of filled areas.
ImgOptions.setSmoothingMode(SmoothingMode.HIGH_QUALITY);
// sets the type of compression to apply when saving generated images to the TIFF format.
ImgOptions.setTiffCompression(TiffCompression.CCITT_3);
// save in visio file into image of choice
vsdxtoImages.save("visiofiletoimage_Out.jpeg", ImgOptions);
Java Code to Convert Visio to SVG
Diagram vsdxTosvg = new Diagram("sourceFile.vsdx");
SVGSaveOptions svgOpts = new SVGSaveOptions();
svgOpts.setDefaultFont("MS Gothic");
// sets the 0-based index of the first page to render. Default is 0.
svgOpts.setPageIndex(0);
// set page size
PageSize pgSize = new PageSize(PaperSizeFormat.A_1);
svgOpts.setPageSize(pgSize);
vsdxTosvg.save("visio-to-svg.svg", svgOpts);
 

Convert Visio to PDF and HTML

API is capable of converting visio formats to PDF as well as in HTML. Just use SaveFileFormat .PDF and SaveFileFormat.HTML within save method as parameter. And for special settings developers can use PdfSaveOptions and HTMLSaveOptions classes.

Java Code for Visio to PDF Conversion
// call the diagram constructor to load diagram from a VSDX file
Diagram vsdxtopdf = new Diagram("sourfile.vsdx");
// Options when saving a diagram into the PDF format
PdfSaveOptions pdfOpts = new PdfSaveOptions();
// discard saving background pages of the Visio diagram
pdfOpts.setSaveForegroundPagesOnly(true);
// specify the quality of JPEG compression for images (if JPEG compression is used). Default is 95.
pdfOpts.setJpegQuality(100);
// specify default font name
pdfOpts.setDefaultFont("Arial");
// conformance level for generated PDF document.
pdfOpts.setCompliance(PdfCompliance.PDF_15);
// sets a digital signature details. If not set, then no signing will be performed.
pdfOpts.setDigitalSignatureDetails(new PdfDigitalSignatureDetails(cert, "Test Signing", "Aspose Office", DateTime.getNow(), PdfDigitalSignatureHashAlgorithm.SHA_256));
// set encription details
PdfEncryptionDetails encriptionDetails = new PdfEncryptionDetails("user password", "Owner Password", PdfEncryptionAlgorithm.RC_4_128);
pdfOpts.setEncryptionDetails(encriptionDetails);
// sets the number of pages to render in PDF.
pdfOpts.setPageCount(2);
// sets the 0-based index of the first page to render. Default is 0.
pdfOpts.setPageIndex(0);
// set page size
PageSize pgSize = new PageSize(PaperSizeFormat.A_1);
pdfOpts.setPageSize(pgSize);
// save in visio file into PDF
vsdxtopdf.save("UsePDFSaveOptions_Out.pdf", pdfOpts);
Java Code to Convert Visio to HTML File
// call the diagram constructor to load diagram from a VSDX file
Diagram vsdxtohtml = new Diagram("sourceFile.vsdx");
// Options when saving a diagram into the HTML format
HTMLSaveOptions htmlOpt = new HTMLSaveOptions();
htmlOpt.setDefaultFont("MS Gothic");
// sets the number of pages to render in HTML.
htmlOpt.setPageCount(2);
// sets the 0-based index of the first page to render. Default is 0.
htmlOpt.setPageIndex(0);
// set page size
PageSize pgSize = new PageSize(PaperSizeFormat.A_1);
htmlOpt.setPageSize(pgSize);
// discard saving background pages of the Visio diagram
htmlOpt.setSaveForegroundPagesOnly(true);
// specify whether to include the toolbar or not. Default value is true.
htmlOpt.setSaveToolBar(false);
// set title of the HTML document
htmlOpt.setTitle("Title goes here");
// save visio file in HTML file format
vsdxtohtml.save("UseHTMLSaveOptions_Out.html", htmlOpt);