Articles in this section
Category / Section

Exporting Report to TIFF Format

Published:
Updated:

Bold Reports currently does not have the ability to directly export reports in TIFF format. However, it can generate a TIFF file from a PDF stream. This article will provide a detailed explanation of how to generate a TIFF file using Bold Reports Writer.

Required NuGet Packages:

Steps:

  1. Create a Bold Reports writer application and get the PDF stream of the report.
[HttpGet]
public IActionResult GetTIFF()
{
           // Here, we have loaded the sales-order-detail sample report from application the folder wwwroot\Resources.
           FileStream reportStream = new FileStream(_hostingEnvironment.WebRootPath + @"\Resources\sales-order-detail.rdl", FileMode.Open, FileAccess.Read);
           BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
           WriterFormat format = WriterFormat.PDF;
           string type = "pdf";
           writer.LoadReport(reportStream);    
           MemoryStream memoryStream = new MemoryStream();
           writer.Save(memoryStream, format);
           ......
           .....
} 
  1. Utilize the Syncfusion EJ2 PdfViewer library to convert the PDF stream into images.
[HttpGet]
public IActionResult GetTIFF()
{
           .....
           //Uses the Syncfusion.EJ2.PdfViewer assembly.
           PdfRenderer pdfExportImage = new PdfRenderer();
           pdfExportImage.Load(memoryStream);
           //Exports the PDF document pages into images.
           SKBitmap[] images = pdfExportImage.ExportAsImage(0, pdfExportImage.PageCount - 1);
           ......

} 
  1. Dynamically create bitmaps from the images converted from PDF stream and adjust the resolution if necessary.
[HttpGet]
public IActionResult GetTIFF()
{
    ......
   // Convert PDF to images
   SKBitmap[] images = ConvertPDFToImages();

   // Dynamically create bitmaps from the images and adjust the resolution if needed
   List<Bitmap> bitmaps = new List<Bitmap>();
   foreach (SKBitmap image in images)
   {
       MemoryStream stream = new MemoryStream();
       image.Encode(stream, SKEncodedImageFormat.Jpeg, 100);
       Bitmap bitmapImage = new Bitmap(stream);
       Bitmap bitmapWithResolution = new Bitmap(bitmapImage.Width, bitmapImage.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
       bitmapWithResolution.SetResolution(1200, 1200); // 1200 dpi resolution
       using (Graphics g = Graphics.FromImage(bitmapWithResolution))
       {
           g.DrawImage(bitmapImage, 0, 0, bitmapImage.Width, bitmapImage.Height);
       }
       bitmaps.Add(bitmapWithResolution);
   }
   ......
   return Ok("TIFF File Exported");
} 
  1. Downloading the Exported TIFF:
  • The resulting TIFF image, named “Output.tiff,” is saved and made available for download on the client side.
    image.png
ReportWriterWithTIFF.zip
Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied