Will you please look at the Visio Stencils (.VSS) files on the following page and let me know why they render to blank PDFs? Specifically, the Icons as Microsoft Visio Stencils (.vss) files.
Hi Per,
Thank you for contacting support. Aspose.Diagram API mimics the behavior Microsoft Visio and generates an empty PDF. Are you looking to save icons of stencil shapes in the PDF file? If so, then you can iterate through the masters and retrieve an icon stream of each shape. Later, you can insert these icons in a new Visio drawing, adjust page size, and then save to the PDF format. Please refer to these help topics: Get Icons of Various Visio Shapes, Create a new Visio Drawing and Import Bitmap Image as a Visio Shape
Thanks for the information. I’ll give this a shot. Do you have a strategy for placing the icon bitmaps in a new Visio drawing? I suppose there could be any number of icons, and they could possibly have different sizes too?
Hi Per,
sharpened:How do you get all icons in the stencils librar, not just the master icon?
{
// get Bitmap stream of each master here
}
Thanks, this works but I get really small, low-quality, pixelated bitmaps. How can I adjust the size of the output bitmaps? I assume the stencil shapes are vectors, which should be able to be adjusted to a greater width/height to get a higher quality image? I’m using the 3015.vss file from the page I originally referenced.
Hi Per,
sharpened:Also, the color of the output image shapes isn’t the same. I uploaded a sample screenshot from Visio versus what I get with the bitmap save.
System.Drawing.Bitmap.Size is a read-only property, and I can’t assign it. How do you set the output size for the bitmap file?
Hi Per,
sharpened:System.Drawing.Bitmap.Size is a read-only property, and I can’t assign it. How do you set the output size for the bitmap file?
Diagram stencil = new Diagram(@“C:\AD\test926\3015.vss”);
int count = 0;
// Get master
foreach (Master master in stencil.Masters)
{
count = count++;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(master.Icon))
{
// load memory stream into bitmap object
// resize the image
Bitmap resized = new Bitmap(bitmap, new Size(bitmap.Width * 2, bitmap.Height * 2));
// Save as png format
resized.Save(@“C:\AD\test926\MasterIcon_out”+count+".png", Imaging.ImageFormat.Png);
}
}
sharpened:These output images have a greenish color and are low quality images, whereas the stencils viewed in Visio are blue.
Thanks. The problem I have with this resizing approach is that it just blows up the low quality images, making them blurry and arguably worse than just leaving them in their original size. Attached is an example.
Hi Per,
// add master from an existing stencil
diagram.AddMaster(@“C:\AD\test926\3015.vss”, “100BaseT hub”);
// get Visio page
Aspose.Diagram.Page srcPage = diagram.Pages[0];
// remove background page
srcPage.BackPage = null;
long shapeID = diagram.AddShape(0, 0, “100BaseT hub”, 0);
Aspose.Diagram.Shape shape = srcPage.Shapes.GetShape(shapeID);
// resize shape
shape.SetWidth(2 * shape.XForm.Width.Value);
shape.SetHeight(2 * shape.XForm.Height.Value);
// move shape to the origin corner
double shapeWidth = shape.XForm.Width.Value;
double shapeHeight = shape.XForm.Height.Value;
shape.MoveTo(shapeWidth * 0.5, shapeHeight * 0.5);
// trim page size
srcPage.PageSheet.PageProps.PageWidth.Value = shapeWidth;
srcPage.PageSheet.PageProps.PageHeight.Value = shapeHeight;
// specify saving options
ImageSaveOptions opts = new ImageSaveOptions(SaveFileFormat.PNG);
// set page count to save
opts.PageCount = 1;
// set starting index of the page
opts.PageIndex = 0;
// save it
diagram.Save(@“C:\AD\test926\Output.png”, opts);
Hi Per,
{
var ressetting = new Aspose.Imaging.ResolutionSetting();
ressetting.HorizontalResolution = 300;
ressetting.VerticalResolution = 300;
var jpegoptions = new Aspose.Imaging.ImageOptions.JpegOptions();
jpegoptions.ResolutionSettings = ressetting;
jpegoptions.Quality = 100;
img.Save(@“C:\AD\test926\Aspose.Imaging_MasterIcon.jpg”, jpegoptions);
}
Thank you for the sample code. Is there a way to iterate through stencils and print each stencil and its Name in a grid layout, starting from the upper left of the diagram, and then output that diagram to PDF? I do not want to save the stencils as bitmaps first if I can avoid it.
Also, from your bitmap output code above where you showed how to resize and then output the bitmap, it doesn’t resize the shape for the example you showed. All it does is add whitespace padding to the output PNG. I attached output examples so you can see what I mean from sample code below:
// resize shape Output-3x.png
shape.SetWidth(3 * shape.XForm.Width.Value);
shape.SetHeight(3 * shape.XForm.Height.Value);
// resize shape Output-2x.png
shape.SetWidth(2 * shape.XForm.Width.Value);
shape.SetHeight(2 * shape.XForm.Height.Value);
// resize shape Output-1x.png
shape.SetWidth(shape.XForm.Width.Value);
shape.SetHeight(shape.XForm.Height.Value);
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #008f00}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas}
Hi Per,
int pageindex = 0;
// get page by index
Page page = diagram.Pages[pageindex];
// retrieve page’s statistics
double pagewidth = page.PageSheet.PageProps.PageWidth.Value;
double pageheight = page.PageSheet.PageProps.PageHeight.Value;
double pageleftmargin = page.PageSheet.PrintProps.PageLeftMargin.Value;
double pagerightmargin = page.PageSheet.PrintProps.PageRightMargin.Value;
double pagetopmargin = page.PageSheet.PrintProps.PageTopMargin.Value;
double pagebottommargin = page.PageSheet.PrintProps.PageBottomMargin.Value;
int mastercount = 0;
// lets place master shapes with same width and height as 2
// here 2 is the width of master shape
// e.g. if cols is 4, then we can place 4 shapes in a row
int cols = ((int)Math.Floor(pagewidth - pageleftmargin - pagerightmargin)) / 2;
// here 2 is the height of master shape
int rows = ((int)Math.Floor(pageheight - pagetopmargin - pagebottommargin)) / 2;
// here 1 is the half of master shape’s width
double pinx = pageleftmargin + 1;
// here 1 is the half of master shape’s height
double piny = pageheight - 1 - pagetopmargin;
foreach (Master master in diagram.Masters)
{
long shapeid = 0;
if (mastercount < cols)
shapeid = diagram.AddShape(pinx + mastercount*2, piny, 2, 2, master.Name, pageindex);
else
{
mastercount = 0;
piny = piny - 2;
rows = rows - 1;
if (rows == 0)
break;
shapeid = diagram.AddShape(pinx + mastercount * 2, piny, 2, 2, master.Name, pageindex);
}
Aspose.Diagram.Shape shape = diagram.Pages[pageindex].Shapes.GetShape(shapeid);
shape.Text.Value.Add(new Txt(master.Name));
mastercount = mastercount+1;
}
diagram.Save(@“C:\Diagram\testdiagram2001\Output.pdf”, SaveFileFormat.PDF);
Thank you for giving this sample code. I actually didn’t expect you to do algorithm work yourself, so thanks for working with me here.
Hi Per,
spurgeon:Also, from your bitmap output code above where you showed how to resize and then output the bitmap, it doesn’t resize the shape for the example you showed. All it does is add whitespace padding to the output PNG. I attached output examples so you can see what I mean from sample code below:
Hi Per,
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>long<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> shapeID = diagram.AddShape(0, 0, “100BaseT hub”, 0);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
Aspose.Diagram.Shape shape = srcPage.Shapes.GetShape(shapeID);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// setting shape’s text as master name
shape.TextXForm.TxtPinX.Ufe.F = “Width+TxtWidth/2”;<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
shape.TextXForm.TxtPinY.Ufe.F = “Height+TxtHeight/2”;
Thanks, but I don’t see the text labels on the output PNGs. Is this because you trim the page size to the shapeWidth and shapeHeight and it clips the text? Can you please provide the complete code sample and verify the output?