You can read all the details at: Protect or Unprotect Visio Diagram or Shapes from Changes in Java
Last active
December 23, 2021 07:21
-
-
Save aspose-com-gists/fcf8a76ee5c0374c7be5305ff579e8ff to your computer and use it in GitHub Desktop.
Java Protect Unprotect Visio Diagram File or Shapes from Changes Programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input Visio diagram file | |
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd"); | |
// Protect Background, Shapes, Master shapes, and, Styles of Visio file | |
diagram.getDocumentSettings().setProtectBkgnds(BOOL.TRUE); | |
diagram.getDocumentSettings().setProtectMasters(BOOL.TRUE); | |
diagram.getDocumentSettings().setProtectShapes(BOOL.TRUE); | |
diagram.getDocumentSettings().setProtectStyles(BOOL.TRUE); | |
// Save protected output diagram file | |
diagram.save(dataDir + "VisioDiagramProtection_Out.vdx", SaveFileFormat.VDX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input diagram | |
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd"); | |
// Get page by name | |
Page page = diagram.getPages().getPage("Flow 1"); | |
// Get shape by ID | |
Shape shape = page.getShapes().getShape(1); | |
// Set protections | |
shape.getProtection().getLockAspect().setValue(BOOL.TRUE); | |
shape.getProtection().getLockCrop().setValue(BOOL.TRUE); | |
shape.getProtection().getLockCustProp().setValue(BOOL.TRUE); | |
shape.getProtection().getLockDelete().setValue(BOOL.TRUE); | |
shape.getProtection().getLockHeight().setValue(BOOL.TRUE); | |
shape.getProtection().getLockMoveX().setValue(BOOL.TRUE); | |
shape.getProtection().getLockMoveY().setValue(BOOL.TRUE); | |
shape.getProtection().getLockRotate().setValue(BOOL.TRUE); | |
shape.getProtection().getLockTextEdit().setValue(BOOL.TRUE); | |
// Save protected output visio diagram | |
diagram.save(dataDir + "VisioShapeProtection_Out.vdx", SaveFileFormat.VDX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the protected input Visio diagram file | |
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd"); | |
// Unprotect Background, Shapes, Master shapes, and, Styles | |
diagram.getDocumentSettings().setProtectBkgnds(BOOL.FALSE); | |
diagram.getDocumentSettings().setProtectMasters(BOOL.FALSE); | |
diagram.getDocumentSettings().setProtectShapes(BOOL.FALSE); | |
diagram.getDocumentSettings().setProtectStyles(BOOL.FALSE); | |
// Save unprotected output diagram file | |
diagram.save(dataDir + "VisioDiagram_Unprotected.vdx", SaveFileFormat.VDX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input Visio diagram | |
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd"); | |
// Get page by name | |
Page page = diagram.getPages().getPage("Flow 1"); | |
// Get shape by ID | |
Shape shape = page.getShapes().getShape(1); | |
// Unprotect Visio shapes | |
shape.getProtection().getLockAspect().setValue(BOOL.FALSE); | |
shape.getProtection().getLockCrop().setValue(BOOL.FALSE); | |
shape.getProtection().getLockCustProp().setValue(BOOL.FALSE); | |
shape.getProtection().getLockDelete().setValue(BOOL.FALSE); | |
shape.getProtection().getLockHeight().setValue(BOOL.FALSE); | |
shape.getProtection().getLockMoveX().setValue(BOOL.FALSE); | |
shape.getProtection().getLockMoveY().setValue(BOOL.FALSE); | |
shape.getProtection().getLockRotate().setValue(BOOL.FALSE); | |
shape.getProtection().getLockTextEdit().setValue(BOOL.FALSE); | |
// Save output Visio diagram with unprotected shapes | |
diagram.save(dataDir + "VisioShape_unprotect.vdx", SaveFileFormat.VDX); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment