Microsoft® Visio Conversão de formatos por meio de Python
Converta diagramas MS Visio em HTML, PDF e imagens, incluindo JPG, BMP, PNG, TIFF para criar aplicativos de plataforma cruzada Python.
Para qualquer solução de renderização de formatos Microsoft Visio, como projetar fluxogramas e diagramas de fluxo de negócios etc. Python Visio API facilita todos os desenhos complexos de maneira fácil. Carregar arquivo de origem usando Diagram classe e chame o método save com os parâmetros apropriados.
Arquivos Visio de conversão entre
Os programadores podem converter facilmente os formatos VSDX, VSX, VTX, VDX, VSSX, VSTX, VSDM, VSSM, VSTM, bem como carregar VDW, VSD, VSS, VST e renderiza para PDF, HTML e Imagens. Considerando o cenário de VSDX a VDX, o processo é carregar o arquivo de origem VSDX usando a classe diagram e chamar o método save fornecendo o arquivo de saída e SaveFileFormat como parâmetros.
Python Código para conversão de VSDX em 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 para conversão de imagens
Para conversão genérica, o processo de conversão de visio arquivos em imagens é o mesmo. Basta carregar o arquivo por meio da classe Diagram e chamar o método save com o arquivo de saída e os parâmetros de saída SaveFileFormat. E sempre que houver necessidade de definir opções específicas, os desenvolvedores podem usar a classe ImageSaveOptions enquanto convertem diagram páginas em imagens e SVGSaveOptions para conversão SVG.
Python Código para converter Visio em formatos de imagem
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); |
Python Código para converter Visio em 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); |
Converter Visio para PDF e HTML
API é capaz de converter formatos visio em PDF, bem como em HTML. Apenas use SaveFileFormat .PDF e SaveFileFormat.HTML dentro do método save como parâmetro. E para configurações especiais, os desenvolvedores podem usar as classes PdfSaveOptions e HTMLSaveOptions.
Python Código para conversão de Visio para 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); |
Python Código para converter Visio em arquivo HTML
// 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); |