Microsoft® Visio Formatkonvertering via Java

Konvertera MS Visio-diagram till HTML, PDF och bilder inklusive JPG, BMP, PNG, TIFF för att bygga plattformsoberoende Java-applikationer.

 

För alla Microsoft Visio-format underlättar renderingslösningar som design av flödesscheman och affärsflödesdiagram etc. Java Visio API alla komplexa ritningar på ett enkelt sätt. Ladda källfilen med hjälp av Diagram klass och anropa sparmetoden med lämpliga parametrar.

Interkonvertering Visio-filer

Programmerare kan enkelt konvertera formaten VSDX, VSX, VTX, VDX, VSSX, VSTX, VSDM, VSSM, VSTM samt laddar VDW, VSD, VSS, VST och renderar till PDF, HTML och bilder. Med tanke på scenariot från VSDX till VDX är processen att ladda källfilen VSDX med klassen diagram och anropa sparmetoden genom att tillhandahålla utdatafil och SaveFileFormat .VDX som parametrar.

Java Kod för omvandling från VSDX till VDX
// 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 till bildkonvertering

För generisk konvertering är processen att konvertera visio filer till bilder densamma. Ladda bara filen via klassen Diagram och anropa sparmetoden med utdatafil och SaveFileFormat-utgångsparametrar. Och närhelst det finns behov av att definiera specifika alternativ kan utvecklare använda klassen ImageSaveOptions medan de konverterar diagram-sidor till bilder och SVGSaveOptions för SVG-konvertering.

Java Kod för att konvertera Visio till bildformat
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 Kod för att konvertera Visio till 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);
 

Konvertera Visio till PDF och HTML

API kan konvertera visio-format till PDF såväl som i HTML. Använd bara SaveFileFormat .PDF och SaveFileFormat.HTML inom sparmetoden som parameter. Och för speciella inställningar kan utvecklare använda klasserna PdfSaveOptions och HTMLSaveOptions.

Java Kod för konvertering från Visio till PDF
// 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 Kod för att konvertera Visio till HTML-fil
// 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);