Print area when rendering

Hello team,



I have converted 0_27.vsd to 0_27.pdf with Aspose.Diagram. Pease find a error point with 0_27_00000001.jpg,

-Print area



For your information, I have attached a PDF(0_27_SaveAsVisio.pdf) which is created by SaveAs of Visio.



This is my code.

------------

public static MemoryStream ConvertDocumentToPdfStream(string docName, MemoryStream docStream)

{

MemoryStream pdfStream = new MemoryStream();



try

{

// Instantiate the License class

Aspose.Diagram.License license = new Aspose.Diagram.License();

license.SetLicense(“Aspose.Total.lic”);



// Convert .ppt and .pptx file to PDF.

Diagram diagram = new Diagram(docStream);

diagram.Save(pdfStream, Aspose.Diagram.Saving.SaveOptions.CreateSaveOptions(SaveFileFormat.PDF));

return pdfStream;

}

finally

{

}

}

------------

Thank you,

PFU DSOL2

Hi,


Thank you for contacting support. We managed to replicate the said problem of rendering the non-print area of drawing in the PDF. It has been logged under the ticket ID DIAGRAMNET-51247 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

Furthermore, you can skip the rendering of background pages by modifying your code 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;”>// Convert .ppt and .pptx file to PDF. <span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
Diagram diagram = <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);”> Diagram(docStream);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// initialize PdfSaveOptions class object<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>
PdfSaveOptions opts = <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;”> PdfSaveOptions();<span 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 flag of Foreground Pages only<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>
opts.SaveForegroundPagesOnly = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>true<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>;<span 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;”>// save in PDF format<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
diagram.Save(pdfStream, opts);
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>

The issues you have found earlier (filed as DIAGRAMNET-51247) have been fixed in Aspose.Diagram for .NET 17.5.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hello team,



Similar phenomenon still happpens when converting to images with Aspose.Diagram 17.5



Thank you,

PFU DSOL2

Hi,


Thank you for the details. Kindly let us know in which image format you are saving the source Visio drawing. When we saved your source Visio drawing into the JPG format using both Aspose.Diagram for .NET 17.5 and Microsoft Visio application, the output JPGs are same. Aspose.Diagram API mimics the behavior of the Microsoft Visio application.

Hello team,



Thank you for your support.



In my environment,



OK When converting to PDF with Aspose.Diagram 17.5.0 (0_27.pdf)

NG: When converting to Image with Aspose.Diagram 17.5.0 (0_27_00000001.jpg)



This is my code for converting to image.

-------------

public static List ConvertVisioToImage(string docName, MemoryStream docStream, Dictionary config)

{

try

{

var pageInfoList = new List();



// Get config setting

string docRootDir = config[“DocumentsFilePath”];

int dpi = int.Parse(config[“ImageDPI”]);

int thumbMaxH = int.Parse(config[“ThumbnailMaxHeight”]);

int thumbMaxW = int.Parse(config[“ThumbnailMaxWidth”]);

int maxPageNum = int.Parse(config[“DocumentMaxPageNum”]);

double readScale = double.Parse(config[“ImageReadScale”]);

int readDpi = Convert.ToInt32(dpi * readScale);



// Create images directory

string pageImgDir = docRootDir;

if (!Directory.Exists(pageImgDir))

Directory.CreateDirectory(pageImgDir);



// Get the encoder of JPEG

//ImageCodecInfo jpgEncoder = GetCodecInfo();

//EncoderParameters encParams = GetEncoderParams();



//EncoderParameters encParams = GetEncoderParams(int.Parse(config[“ImageJpegQuality”]));



// Instantiate the License class

Aspose.Diagram.License license = new Aspose.Diagram.License();

license.SetLicense(“Aspose.Total.lic”);



// Convert .doc and .docx file to PDF.

Diagram diagram = new Diagram(docStream);





//int totalPageCount = 0;

for (int i = 0; (i < maxPageNum); i++)

{

// Export image file

//Page page = diagram.Pages.GetPage(i);

if (diagram.Pages[i].Background == Aspose.Diagram.BOOL.True) { continue; }



foreach (Aspose.Diagram.Shape shape in diagram.Pages[i].Shapes)

{

if (shape.Name == “”)

{



}

}



foreach (Layer layer in diagram.Pages[i].PageSheet.Layers)

{

if (layer.Visible.Value == Aspose.Diagram.BOOL.True)

{



}

}







var options = new Aspose.Diagram.Saving.ImageSaveOptions(SaveFileFormat.JPEG);

options.ExportHiddenPage = true;

options.PageIndex = i;

options.JpegQuality = int.Parse(config[“ImageJpegQuality”]);

options.Resolution = readDpi;

string imgFile = string.Format("{0}_{1:D8}.jpg",

Path.GetFileNameWithoutExtension(docName), i + 1);

string imgPath = Path.Combine(pageImgDir, imgFile);

diagram.Save(imgPath, options);



// Export thumbnail file

//string thumbFilename = string.Format(@"{0}_thumb.jpg", Path.GetFileNameWithoutExtension(imgPath));

//string thumbPath = Path.Combine(Path.GetDirectoryName(imgPath), thumbFilename);

//using (Bitmap bitmap = new Bitmap(imgPath))

//{

// float scale = (float)Math.Min((double)thumbMaxW / bitmap.Width,

// (double)thumbMaxH / bitmap.Height);

// int thumbW = System.Convert.ToInt32(bitmap.Width * scale);

// int thumbH = System.Convert.ToInt32(bitmap.Height * scale);

// using (Bitmap thumbBmp = new Bitmap(thumbW, thumbH))

// {

// thumbBmp.SetResolution(dpi, dpi);



// using (Graphics graph = Graphics.FromImage(thumbBmp))

// {

// graph.DrawImage(bitmap, 0, 0, thumbW, thumbH);

// }

// thumbBmp.Save(thumbPath, jpgEncoder, encParams);

// }

//}



// TODO Create OCR XML



// Add PageInfo List

pageInfoList.Add(imgPath);

}



// return results with flag of max page limit over

return pageInfoList;

}

finally

{

}

}



-------------

They are parameters.



// Get config setting

Create Appseting key value for async function

Dictionary<string, string> config = new Dictionary<string, string>();



config.Add(“DocumentsFilePath”, outDir);

config.Add(“ImageDPI”, “96”);

config.Add(“ImageReadScale”, “1.25”);

config.Add(“ThumbnailMaxHeight”, “252”);

config.Add(“ThumbnailMaxWidth”, “210”);

config.Add(“ImageJpegQuality”, “80”);

config.Add(“DocumentMaxPageNum”, “1000”);

-------------



Thank you,

PFU DSOL2

Hi,


Thank you for the inquiry. Aspose.Diagram API mimics the behavior Microsoft Visio and saves all shapes as shown in your snapshot. We have attached an output of the Microsoft Visio application to this reply. Please let us know in case of any confusion or questions.

Hello team,



Thank you for your support.



I understand Aspose Diagram API mimics the behavior Microsoft Visio.



I would like to get a image with only Visio’s print area(same as 0_27.pdf’s size) when convertiong to image.

Do you have the function to control area size when converting to image?



Thank you,

PFU DSOL2

Hi,


Thank you for the inquiry. We have logged a feature request under the ticket ID DIAGRAMNET-51261 in our issue tracking system to convert the specific area of a drawing to image. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

@PFU.DSOL2,
In reference to the ticket ID DIAGRAMNET-51261, please download and try the latest Hotfix version: Aspose.Diagram for .NET 17.8.1. Please try the following code example:

C#

// load a Visio drawing
Diagram diagram = new Diagram(@"e:\\test.vsdx");
ImageSaveOptions Options = new ImageSaveOptions(SaveFileFormat.PNG);
// specify region
Options.Area = new RectangleF(0, 0, 1, 1);
// save into the image format
diagram.Save("e:\\area.png", Options);

Hello team,

Thank you for providing Hotfix however the function I hope is a llittle different.
My request was not clear and I am sorry for that.

(A) Conversion to PDF by ASPOSE
0_27.vsd.pdf (841 KB)

(B) Conversion to Image by ASPOSE
1.jpg (602.2 KB)

Please compare page 1 of A with page 1 of B. The output area is different between these.

I hope the function such as:

 Options.SameAsPdfConversionArea = true;
 diagram.Save("e:\\area.png", Options);

Result:: Aspose outputs image the area of which is same as area of PDF

Thank you,

@PFU.DSOL2,
Aspose.Diagram for .NET API mimics the behavior of the Microsoft Visio application and after saving your Visio drawing with Microsoft Visio application, the output image is the same as you have shared. You can convert a Pdf page to an image using Aspose.Pdf for .NET API. Please refer to this help topic: Convert PDF Pages to JPEG Images

Thank you for suggesting workaround.

I am afraid converting pdf pages to jpeg images will be unhappy for me because of processing time of convertiing(vsd->pdf->image)
I understand Aspose.Diagram for .NET API mimics the behavior of the Microsoft Visio application and I suggested by setting new mode to pdf conversion.

Is it difficult that pdf conversion has new mode to change output area?

@PFU.DSOL2,
We do not incorporate any enhancement or feature which does not obey the behavior Microsoft Visio application. However, we will discuss this matter with our product team, and then let you know.

If you are facing any performance issue, then kindly let us know. We recommend our clients to post each their issue proactively in the Aspose forums.

@PFU.DSOL2,

We have added this feature request under the ticket ID DIAGRAMNET-51349 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Thank you for adding ticket as a future request because my customer has a strongly request for this feature. I hope that Aspose API implements this feature soon. Thank you.

@PFU.DSOL2,
Sure, we will let you know once it is resolved.

@PFU.DSOL2,
The linked ticket ID DIAGRAMNET-51261 has been fixed. Please download and try the new version 17.9 of Aspose.Diagram for .NET API.

@PFU.DSOL2,
The linked ticket ID DIAGRAMNET-51349 has been resolved. If there is no issue in the quality assurance phase, then this fix will be included in the next version 17.10 of Aspose.Diagram for .NET API. We will notify you once the next version is published.

@PFU.DSOL2,
In reference to the ticket ID DIAGRAMNET-51349, please download and try the latest Hotfix version: Aspose.Diagram for .NET 17.9.1 and let us know how that goes into your environment.

[C#]

Diagram map = new Diagram(dataDir + "Drawing1.vsdx")
ImageSaveOptions opts = new ImageSaveOptions(SaveFileFormat.JPEG);
opts.SameAsPdfConversionArea = true;
map.Save(dataDir + "out.jpg", opts);