Page 1 of 1

Exporting a specific report page to an image

Posted: Wed May 18, 2016 10:19 am
by Abed Hamodi
Hi,
I am trying to export a specific page from report contains many pages to an image, and it always return the same page which the first on,
I tried to pass the page number in the export settings and it ignored it, below is the code, thanks in advance:

Code: Select all

 
         
           StiBusinessObject  currentBusinessObject = businessObject;
           StiReport report = new StiReport();
           string units = "";
             if (currentBusinessObject != null)
            {
                report.Dictionary.BusinessObjects.Clear();
                report.Dictionary.BusinessObjects.Add(currentBusinessObject);
                report.RegBusinessObject(currentBusinessObject.Category, currentBusinessObject.Name, currentBusinessObject.BusinessObjectValue);                
            }
        
            report.Dictionary.SynchronizeBusinessObjects();
            report.Load(documenttypeTemplate.TemplateBody);
            report.Render();

            string result= report.SaveDocumentToString();
            MemoryStream memoryStream = new MemoryStream();

            Stimulsoft.Report.Components.StiMargins margins = new Stimulsoft.Report.Components.StiMargins() { Bottom = 0, Right = 0, Left = 0, Top = 0 };
            foreach (StiPage page in report.RenderedPages)
            {
                page.Margins = margins;
            }
             units = report.ReportUnit.ToString();


            string EditableFields = "";
            if (documentOut.EditableFields != null)
            {
                 EditableFields = System.Text.Encoding.UTF8.GetString(documentOut.EditableFields);
                 Stream editableFieldsStream;
                 using (editableFieldsStream = new MemoryStream())
                 {
                     editableFieldsStream.Write(documentOut.EditableFields, 0, documentOut.EditableFields.Length);

                     editableFieldsStream.Seek(0, SeekOrigin.Begin);
                     report.LoadEditableFields(editableFieldsStream);

                 }
            }

            report.Unit = new StiCentimetersUnit();
            report.ReportUnit = StiReportUnitType.Centimeters;

          report.ExportDocument(StiExportFormat.ImagePng, memoryStream, new Stimulsoft.Report.Export.StiPngExportSettings() { PageRange = new Stimulsoft.Report.StiPagesRange(StiRangeType.Pages, Pagenumber.ToString(), Pagenumber), MultipleFiles = true, CutEdges = true, ImageResolution = 200, ImageFormat = StiImageFormat.Color }); 

Re: Exporting a specific report page to an image

Posted: Thu May 19, 2016 6:16 am
by HighAley
Hello.

Sorry, we don't see where you define Pagenumber.
Please, check it and if it doesn't help, send us a sample project that reproduces the issue.

Thank you.

Re: Exporting a specific report page to an image

Posted: Sun May 22, 2016 10:56 am
by Abed Hamodi
thanks for the reply , the page number is Parameter that pass to the api in order to export a page, if i passed the pagenumber = 3, i need to export the 3rd page of the report.

Re: Exporting a specific report page to an image

Posted: Mon May 23, 2016 8:23 am
by HighAley
Hello.

Your code works right.
Please, check the value of the Pagenumber.
If you still have an issue, please, send us a sample project that reproduces it.

Thank you.

Re: Exporting a specific report page to an image

Posted: Sun May 29, 2016 8:33 am
by Abed Hamodi
Hello,
after many tries i found that the cause for this problem is the business object, when i didn't connect the business object to the report the export worked fine, when i comment the business object code i could see that the rendered pages number is correct, but when i register it the rendered pages will be always one page, the code for registering the object is below:

if (currentBusinessObject != null)
{
report.Dictionary.BusinessObjects.Clear();
report.Dictionary.BusinessObjects.Add(currentBusinessObject);
report.RegBusinessObject(currentBusinessObject.Category, currentBusinessObject.Name, currentBusinessObject.BusinessObjectValue);
}

report.Dictionary.SynchronizeBusinessObjects();

Re: Exporting a specific report page to an image

Posted: Mon May 30, 2016 9:32 am
by Alex K.
Hello,

Please send us a simple project which reproduces the issue for analysis.

Thank you.