VSS Files Converted to PDF Blank

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.


Network Topology Icons - Doing Business With Cisco - Cisco

var diagram = new Diagram(inputPath, LoadFileFormat.VSS);
diagram.Save(outputPath, SaveFileFormat.PDF);

Aspose.Diagram.dll
6.2.0.0

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?


Also, in the “Get Icons Programming Sample” code you linked, there is a hard-coded 1:

<span class=“pl-en” style=“color: rgb(121, 93, 163); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”>Master<span style=“color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”> <span class=“pl-en” style=“color: rgb(121, 93, 163); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”>master<span style=“color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”> = <span class=“pl-en” style=“color: rgb(121, 93, 163); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”>stencil.Masters.GetMaster<span style=“color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, “Liberation Mono”, Menlo, Courier, monospace; font-size: 12px; white-space: pre; background-color: rgb(255, 255, 255);”>(1);

How do you get all icons in the stencils librar, not just the master icon?

Hi Per,


Thank you for the inquiry. You can place the icon bitmaps anywhere in the Visio drawing. The overload AddShape methods of Page class allow to even set the width and height of an icon or you may not set the width and height to keep the original size. Please refer to this code example: Insert an Image in the Visio Drawing
sharpened:
How do you get all icons in the stencils librar, not just the master icon?
Each shape in the Stencil file has a master from which the Shape object will be created. You can iterate through the each master and retrieve bitmap stream.
[.NET, C#]
foreach (Master master in stencil.Masters)
{
// 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.


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.

Hi Per,


Thank you for the details. The Bitmap file is a raster graphic. You can change its width and height, but the output image will be pixelated.

if you require to set Height = 50 & Width = 100. then
bitmap.Size = new Size(50 , 100);
if you require to change only Height = 50. then
bitmap.Size = new Size(50 , bitmap.Width); // this will set its height only
and if you require to change only Width = 60. then
bitmap.Size = new Size(bitmap.Height, 60); // this will set its width only

Aspose.Imaging API works for the image formats. Unfortunately, there is no way to convert Bitmap to a Vector graphic. We have logged this feature request under ticket ID IMAGINGNET-2275 in our issue tracking system. Your post has also been linked to this ticket. We shall keep you informed regarding any available updates. We are sorry for the inconvenience caused.
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.
How did you create “visio shapes.png” file? Please share the complete steps. We did not notice a difference in color, please also highlight the contrast with help of a screenshot. You might also share on which operating system and device you are viewing it. It will help us to replicate the color difference on our side. Your response is awaited.

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?


The “visio shapes.png” file was created by taking a screenshot from Microsoft Visio (latest version, installed yesterday) when viewing the stencils icons. The aspose-X.png files were output from Aspose.Email the sample code you linked (Get Icons of Various Visio Shapes). These output images have a greenish color and are low quality images, whereas the stencils viewed in Visio are blue.

Also, don’t need vector format output for the stencils (e.g., SVG or EPS), although I suppose it would be cool to have that option in the library.

Hi Per,


We are sorry for the inconvenience caused.
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?
The bitmap constructor allows to resize as below:
[.NET, C#]
// Load stencil file to a diagram object
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
Bitmap bitmap = new Bitmap(stream);
// 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.
We managed to replicate the problem of the greenish color of icons. It has been logged under ticket ID DIAGRAMNET-51160 in our bug tracking system. Your post has also been linked to this ticket. We shall let you know once a significant progress has been made in this regard.

As a workaround, you can set the fill color of a shape as narrated in this help topic: Set the Fill Color of a Visio Shape. Please let us know in case of any further assistance or questions.

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.


I was able to place the stencils into a Visio diagram at an increased size as shapes, and they are rendered clearly at the larger size. I assume this means they’re scaled up as vectors and then rendered as bitmaps on the diagram when converted to PDF. I think I’ll go with this approach for now, and I assume I could then iterate through those placed stencil shapes and export them as bitmaps, although I haven’t tried that yet.

Hi Per,


Thank you for the inquiry. There is another workaround. We have written a sample code below using Aspose.Diagram API. It places a shape in the new Visio drawing, modifies its size, remove blank space of the page, and then convert it to an image.

[.NET, C#]
<span style=“color: rgb(0, 128, 0); background-color: rgb(255, 255, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// create a new drawing
Diagram diagram = new Diagram();
// 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;

// place a shape in the drawing
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,


In addition to the above reply, you can also resize an image using Aspose.Imaging API without the loss of quality. It also removes image blurring.

[.NET, C#]
using (Aspose.Imaging.Image img = Aspose.Imaging.Image.Load(@“C:\AD\test926\aspose-0.png”))
{
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.Resize(img.Width * 2, img.Height * 2, Aspose.Imaging.ResizeType.LanczosResample);
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.


There would be N rows and M columns of stencil icons on a single diagram page, each with its Name printed as a label beside it. Also, I would like to preserve the aspect ratio of the stencil icons within a fixed size square so they don’t get stretched/skewed.

I’m having difficulty understanding the coordinate system of a diagram and how to place icons accordingly. There are floating point numbers (pinX and pinY), but I don’t know how this relates to the diagram size, the max pinX/pinY, resolution, etc.

EDIT: Here’s some sample code I’ve tried that doesn’t do the job. The text boxes and shapes don’t seem to match when placed on the diagram. Also, the grid is messed up.

diagram = new Diagram(inputPath);
Diagram stencils = new Diagram();

int i = 0;
double x = 0;
double y = 12;
foreach (Master master in diagram.Masters)
{
stencils.AddMaster(diagram, master.Name);
long id = stencils.AddShape(x, y, 2, 2, master.Name, 0);
stencils.Pages[0].AddText(x, y, 2, 2, master.Name);
if (i % 10 == 9) {
x = 0;
y -= 2;
} else {
x += 2;
}
i++;
}
stencils.Save(outputPath, SaveFileFormat.PDF);

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);


Do you know why this is? I need to be able to scale the size or else I will have trouble displaying icons consistently across all .vss files.

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,


Thank you for the inquiry. PinX and PinY are the center points of any master shape. If both PinX and PinY values are zero, then master shape’s center would be at left bottom corner of the Visio page. Please try the following code example on your stencil file:

[.NET, C#]
Diagram diagram = new Diagram(@“C:\Diagram\testdiagram2001\3015.vss”);
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.


I get a really funny looking PDF from the code above. I attached the output PDF that was generated with Aspose.Diagram 17.3.0. Did you run the code on the 3015.vss file and get different results?

Hi Per,


Thank you for the details. When you will save drawing in the VDX format, it looks perfect. However, on saving in the PDF format, it renders shapes partially. We have logged this problem under ticket ID DIAGRAMNET-51171 in our bug tracking system.
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:
We managed to replicate the same problem on our side. It has been logged under ticket ID DIAGRAMNET-51172 in our bug tracking system. Your post has also been linked to these tickets. We shall let you know once a significant progress has been made in this regard. We are sorry for the inconvenience caused.

Thanks for your continued support.

Ultimately, I have a customer who does not have Visio but wants to be able to view .vss (and .vssx) stencils with each stencil having an icon and label, and I haven't been able to find a solution to this yet. The view from the Visio 2016 stencil viewer (I've attached a screenshot of it) is an example of the layout I'm trying to achieve, rendered as a PDF. I would also accept bitmap (PNG/JPEG) output at this point. If you have a way that I could achieve this with your API, please let me know.

With whatever issues you've identified for fix, can you please make sure that I have the ability to render stencils and their names as text labels to a non-Visio format, preferably PDF?

Lastly, I tried outputting VDX, VSDX, PDF, and PNG files. Each of the renderings is different (the VDX and VSDX files are shown in Visio 2016). Also, only 20 icons are shown, whereas I believe there are 300 in the 3015.vss file.

Hi Per,


Thank you for the details. To achieve the requirement, you do not need to change the width and height of a shape. When you are setting the width and height of a shape, it does not properly render shapes in non-Visio formats. You can add text to a shape, and then formulate the position of shape’s text. Please modify the code which is already shared in an earlier post as below:

[.NET, C#]
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// place a shape in the drawing <br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// here we are not passing width and height parameters<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<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
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>shape.Text.Value.Add(<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Txt(shape.Master.Name));<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// set text position<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
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”;

Once you save icons in the PNG format, then please use Aspose.Pdf for .NET API to generate a new PDF. You can place icons in the tabular form, and store PDF in the local memory. Please refer to these help topics: Add Image to an Existing PDF and Add Image to a Table’s Cell

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?


Unfortunately, we can’t use the Aspose.Pdf API in our application because we cannot add a 26MB dll, so we’ll have to find another method, or wait for fixes to the Aspose.Diagram library.
I'm going to close this thread from my end, meaning that, at this point, I don't need text labels to be printed next to stencil icons before outputting them to individual PNG files. Also, ticket ID IMAGINGNET-2275 is a low priority for me. I have found another solution where I can output the stencils as PNGs and then view the list of PNGs in an image thumbnail viewer. This solution will work for the 3015.vss file that I referenced, although I've found bugs when trying to output stencils from several other .vss files (0 byte PNG outputs).

I would still like to be able to render stencils placed in a diagram to PDF at some point, but this thread has just become fatiguing at this point. There just seem to be a lot of bugs and limitations for rendering stencils to non Visio formats.