This is a migrated thread and some comments may be shown as answers.

Render report as PNG and set image size

2 Answers 542 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Roman
Top achievements
Rank 1
Iron
Roman asked on 15 Apr 2019, 09:05 AM

Hi there

I'm trying to change the image size of a report when saving it as PNG file. I'm using this code to render the report and save it as PNG file:

private static void RenderReport()
{
    ReportProcessor reportProcessor = new ReportProcessor();
    Hashtable info = new Hashtable();
    info["OutputFormat"] = "PNG";
 
    InstanceReportSource reportSource = new InstanceReportSource();
    reportSource.ReportDocument = new BucherLabel(nSalDocInternalNo, nSalDocItemInternalNo, nSalDocItemNo);
 
    reportProcessor.RenderReport("IMAGE", reportSource, info, CreateStream, out string docName);
    CloseStreams();
}
 
private static Stream CreateStream(string sFileName, string sExtension, Encoding encoding, string sMimeType)
{
    string sPath = $@"K:\Daten\SRM\FileOrder\{nSupplNo}\Labels\";
    sFileName = $"{nSalDocInternalNo},{nSalDocItemInternalNo}";
 
    if (!Directory.Exists(sPath))
        Directory.CreateDirectory(sPath);
 
    string sFilePath = Path.Combine(sPath, $"{sFileName}.{sExtension}");
    FileStream fs = new FileStream(sFilePath, FileMode.Create);
    lStreams.Add(fs);
 
    return fs;
}
 
private static void CloseStreams()
{
    foreach (Stream s in lStreams)
        s.Close();
 
    lStreams.Clear();
}

It works pretty fine. But I don't know how to set the filesize. Is this even possible?

Regards,
Roman

2 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 17 Apr 2019, 02:16 PM
Hi Roman,

I suggest to render the report in EMF as it is vector format, i.e. lossless when resizing. Then you may use the standard image processing in .NET to resize the rendered document and save it with the required image size in PNG.

You may also use the DPI settings in the Image Device Info to control the resolution of the generated image. This will make the image look bigger in smaller resolution.

Regards,
Todor
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Roman
Top achievements
Rank 1
Iron
answered on 18 Apr 2019, 09:14 AM
Hi Todor,

Using EMF format works great, thanks for the solution :)

Regards,
Roman
Tags
General Discussions
Asked by
Roman
Top achievements
Rank 1
Iron
Answers by
Todor
Telerik team
Roman
Top achievements
Rank 1
Iron
Share this question
or