Render report as PNG and set image size

3 posts, 1 answers
  1. Roman
    Roman avatar
    5 posts
    Member since:
    Apr 2019

    Posted 15 Apr Link to this post

    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. Answer
    Todor
    Admin
    Todor avatar
    310 posts

    Posted 17 Apr Link to this post

    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
  3. Roman
    Roman avatar
    5 posts
    Member since:
    Apr 2019

    Posted 18 Apr in reply to Todor Link to this post

    Hi Todor,

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

    Regards,
    Roman
Back to Top