Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 78072

Dynamically Adding Pages to Report Causes Internal Server Error

$
0
0

I have a site that allows users to upload images to the report. The users can upload as many images as they want and the images get appended to the report.

The report viewer initially contains a report and the users images are appended at the button of the report. The way I append the images: I have created a one page report that has an image in the middle of the report. I iterate through all the image paths and add a new report for each image.

 

Here is an example of when the report processes the error. When a user adds 1 image and renders the report the report view looks great but once they add more images and try to render the report the report view crashes.

Below is the Error and Stack Trace:

URL: /api/Reports/clients/160626-95db/instances/160630-aeac/documents/161216-3e80161216-c106/info

"message":"",
"exceptionMessage":"Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index",
"exceptionType":"Telerik.Reporting.Services.Engine.DocumentRenderException",
"stackTrace":" at Telerik.Reporting.Services.Engine.Document.GetDocumentInfo()\r\n at Telerik.Reporting.Services.Engine.ReportEngine.GetDocumentInfo(String clientID, String instanceID, String documentID)\r\n at Telerik.Reporting.Services.WebApi.ReportsControllerBase.GetDocumentInfo(String clientID, String instanceID, String documentID)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()"

 

Here is the report:

namespace LT.Services.Reporting.EFV.Reports.Reports.ScannedImage
{
    partial class rptScannedImage
    {
        #region Component Designer generated code
        /// <summary>
        /// Required method for telerik Reporting designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            Telerik.Reporting.Group group1 = new Telerik.Reporting.Group();
            Telerik.Reporting.ReportParameter reportParameter1 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter2 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter3 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter4 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter5 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.ReportParameter reportParameter6 = new Telerik.Reporting.ReportParameter();
            Telerik.Reporting.Drawing.StyleRule styleRule1 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule styleRule2 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule styleRule3 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule styleRule4 = new Telerik.Reporting.Drawing.StyleRule();
            this.groupFooterSection = new Telerik.Reporting.GroupFooterSection();
            this.groupHeaderSection = new Telerik.Reporting.GroupHeaderSection();
            this.detail = new Telerik.Reporting.DetailSection();
            this.pictureBox1 = new Telerik.Reporting.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            // 
            // groupFooterSection
            // 
            this.groupFooterSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.0520833320915699D);
            this.groupFooterSection.Name = "groupFooterSection";
            this.groupFooterSection.Style.Visible = false;
            // 
            // groupHeaderSection
            // 
            this.groupHeaderSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.0520833320915699D);
            this.groupHeaderSection.Name = "groupHeaderSection";
            this.groupHeaderSection.Style.Visible = false;
            // 
            // detail
            // 
            this.detail.Height = Telerik.Reporting.Drawing.Unit.Inch(1.0000008344650269D);
            this.detail.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.pictureBox1});
            this.detail.Name = "detail";
            this.detail.PageBreak = Telerik.Reporting.PageBreak.After;
            // 
            // pictureBox1
            // 
            this.pictureBox1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(3.9418537198798731E-05D), Telerik.Reporting.Drawing.Unit.Inch(0D));
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(1.0000003576278687D), Telerik.Reporting.Drawing.Unit.Inch(1D));
            this.pictureBox1.Sizing = Telerik.Reporting.Drawing.ImageSizeMode.AutoSize;
            this.pictureBox1.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.None;
            // 
            // rptScannedImage
            // 
            group1.GroupFooter = this.groupFooterSection;
            group1.GroupHeader = this.groupHeaderSection;
            group1.Name = "group";
            this.Groups.AddRange(new Telerik.Reporting.Group[] {
            group1});
            this.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            this.groupHeaderSection,
            this.groupFooterSection,
            this.detail});
            this.Name = "rptScannedImage";
            this.PageSettings.Margins = new Telerik.Reporting.Drawing.MarginsU(Telerik.Reporting.Drawing.Unit.Inch(0D), Telerik.Reporting.Drawing.Unit.Inch(0D), Telerik.Reporting.Drawing.Unit.Inch(0D), Telerik.Reporting.Drawing.Unit.Inch(0D));
            this.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom;
            this.PageSettings.PaperSize = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(8.5D), Telerik.Reporting.Drawing.Unit.Inch(11D));
            reportParameter1.Name = "PageNumber";
            reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer;
            reportParameter1.Value = "1";
            reportParameter2.Name = "ImageToAdd";
            reportParameter2.Value = "D:\\KDrive\\LT001\\LT001001\\001000003.tif";
            reportParameter3.Name = "ImageExists";
            reportParameter3.Type = Telerik.Reporting.ReportParameterType.Boolean;
            reportParameter3.Value = "= True";
            reportParameter4.Name = "RegistrationNumber";
            reportParameter4.Value = "000000000";
            reportParameter5.Name = "IsEmbeddedResource";
            reportParameter5.Value = "= False";
            reportParameter6.Name = "FileResourceName";
            reportParameter6.Value = "LT.Services.Reporting.EFV.Reports.Contents.Images.eSubmission_CoverPage.jpg";
            this.ReportParameters.Add(reportParameter1);
            this.ReportParameters.Add(reportParameter2);
            this.ReportParameters.Add(reportParameter3);
            this.ReportParameters.Add(reportParameter4);
            this.ReportParameters.Add(reportParameter5);
            this.ReportParameters.Add(reportParameter6);
            this.Style.BackgroundColor = System.Drawing.Color.White;
            styleRule1.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Title")});
            styleRule1.Style.Color = System.Drawing.Color.Black;
            styleRule1.Style.Font.Bold = true;
            styleRule1.Style.Font.Italic = false;
            styleRule1.Style.Font.Name = "Tahoma";
            styleRule1.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(18D);
            styleRule1.Style.Font.Strikeout = false;
            styleRule1.Style.Font.Underline = false;
            styleRule2.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Caption")});
            styleRule2.Style.Color = System.Drawing.Color.Black;
            styleRule2.Style.Font.Name = "Tahoma";
            styleRule2.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(10D);
            styleRule2.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            styleRule3.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Data")});
            styleRule3.Style.Font.Name = "Tahoma";
            styleRule3.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(9D);
            styleRule3.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            styleRule4.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("PageInfo")});
            styleRule4.Style.Font.Name = "Tahoma";
            styleRule4.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(8D);
            styleRule4.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            this.StyleSheet.AddRange(new Telerik.Reporting.Drawing.StyleRule[] {
            styleRule1,
            styleRule2,
            styleRule3,
            styleRule4});
            this.Width = Telerik.Reporting.Drawing.Unit.Inch(1.0000393390655518D);
            this.ItemDataBinding += new System.EventHandler(this.rptScannedImage_ItemDataBinding);
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }
        #endregion

        private Telerik.Reporting.DetailSection detail;
        private Telerik.Reporting.GroupHeaderSection groupHeaderSection;
        private Telerik.Reporting.GroupFooterSection groupFooterSection;
        private Telerik.Reporting.PictureBox pictureBox1;

    }
}

Here is the location I add the image to the report

public partial class rptScannedImage : Telerik.Reporting.Report
    {
        private static readonly CacheHelper _cacheHelper = CacheHelper.Instance;
        private Object thisLock = new Object();


        public rptScannedImage()
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        private void rptScannedImage_ItemDataBinding(object sender, EventArgs e)
        {
            lock (thisLock)
            {
                bool imageExists = (bool)this.ReportParameters["ImageExists"].Value;
                int pageNumber = (int)this.ReportParameters["PageNumber"].Value;
                string imageFile = (string)this.ReportParameters["ImageToAdd"].Value;
                bool isEmbeddedResource = (bool)this.ReportParameters["IsEmbeddedResource"].Value;
                string fileResourceName = (string)this.ReportParameters["FileResourceName"].Value;

                if (!imageExists)
                {
                    var txtNotAvailable = new Telerik.Reporting.TextBox();
                    txtNotAvailable.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.5D), Telerik.Reporting.Drawing.Unit.Inch(2.5D));
                    txtNotAvailable.Name = "txtNotAvailable";
                    txtNotAvailable.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(7.5D), Telerik.Reporting.Drawing.Unit.Inch(5.5));
                    txtNotAvailable.Style.Font.Name = "Times New Roman";
                    txtNotAvailable.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(72D);
                    txtNotAvailable.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
                    txtNotAvailable.Value = "Dummy Registered Document Image for " + (string)this.ReportParameters["RegistrationNumber"].Value;
                    this.detail.Items.Add(txtNotAvailable);
                }
                else
                {
                    Image image = null;
                    // if it's not an embedded resourece 
                    if (!isEmbeddedResource)
                    {
                        // we need to clone the image for thread safety
                        image = ReportDataMethod.GetImage(imageFile);
                    }
                    else
                    {
                        image = Reporting.EFV.Reports.ReportDataMethod.GetImageFromResource(fileResourceName);
                    }

                    double width = image.Width / image.HorizontalResolution;
                    double height = image.Height / image.VerticalResolution;
                    SizeU size = new SizeU(Unit.Inch(width), Unit.Inch(height));
                    Telerik.Reporting.Processing.Report rpt = (Telerik.Reporting.Processing.Report)sender;
                    rpt.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Custom;
                    rpt.PageSettings.PaperSize = size;

                    pictureBox1.MimeType = "image/png";
                    pictureBox1.Value = image;
                }
            }
        }

 

Here is the way I append the images in the resolver

    // Add File Attachment to report
                            // Attach image files as pages
// Gets the paths
                            var pngImagePaths = ReportDataMethod.GetFilePaths(eFormID);
                            if (pngImagePaths != null)
                            {
                                var pageCountID = 1;
                                foreach (var imagePath in pngImagePaths)
                                {
                                    // Add cover page (Eventually we will add this to all E-Forms
                                    // Add scanned file
                                    // note that setting filePath or File Resource Name to null will
                                    // cause the preview to crash on reload
                                    PDFToImageParameters fileParams = new PDFToImageParameters()
                                    {
                                        FilePath = imagePath,
                                        FileResourceName = "",
                                        ImageExists = true,
                                        IsEmbeddedResource = false,
                                        PageCount = pageCountID
                                    };
                                    var fileReport = UpdateScannedImageReportWithParams(eFormID, pageCountID == 1 ? "File Attachment" : String.Empty, pageCountID++, fileParams);
                                    book.Reports.Add(fileReport);
                                }
                            }

 

Any help would be appreciated.

 

Thanks!

 


Viewing all articles
Browse latest Browse all 78072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>