Display EMF report quality and PDF

I'm having difficulty displaying an SSRS server report and printing it from code.

Despite the fact that the rendering is successful and the report is printing, the quality results in the graph are poor. The report itself has a 6kx1k high resolution GIF image for the logo.

I made the image below to illustrate the difference between rendering using EMF and PDF:

(PDF on the left, EMF on the right)

As you can see, the font looks great (without pixelation), and the PDF rendering looks good. However, the EMF version is of poor quality, as you can see at the edges of the logo.

Has anyone stumbled upon this and decided it?

I am running SQL Server 2008R2 SP2 (10.50.4000)

Code for displaying a report using EMF

public List<byte[]> Render() { // Setting credentials and reporting services uri ReportExecutionService reportService = new ReportExecutionService { Credentials = _credentials, Url = Settings.Default.ReportingService }; // Prepare report parameter. ExecutionHeader execHeader = new ExecutionHeader(); reportService.ExecutionHeaderValue = execHeader; reportService.LoadReport(_report, null); reportService.SetExecutionParameters(_parameters.ToArray(), "en-us"); // Render bool startup = true; List<byte[]> streams = new List<byte[]>(); int numberOfPages = 0; byte[] result = null; while (startup || result.Length > 0) { startup = false; string devInfo = String.Format(@"<DeviceInfo><OutputFormat>EMF</OutputFormat><PrintDpiX>150</PrintDpiX><PrintDpiY>150</PrintDpiY><StartPage>{0}</StartPage></DeviceInfo>", numberOfPages + 1); string encoding, mimeType, extension; string[] streamIDs = null; Warning[] warnings = null; result = reportService.Render("IMAGE", devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs); if (result.Length > 0) { streams.Add(result); } numberOfPages++; } return streams; } 

Here is the implementation of printdocument

 public class PrintReport : PrintDocument { private int _currentPage; private List<byte[]> _pages; public PrintReport() { } public List<byte[]> Pages { get { return _pages; } set { _pages = value; } } protected override void OnBeginPrint(PrintEventArgs e) { base.OnBeginPrint(e); _currentPage = 0; } protected override void OnPrintPage(PrintPageEventArgs e) { base.OnPrintPage(e); Stream pageToPrint = new MemoryStream(_pages[_currentPage]); pageToPrint.Position = 0; // Load each page into a Metafile to draw it. using (Metafile pageMetaFile = new Metafile(pageToPrint)) { Rectangle adjustedRect = new Rectangle( e.PageBounds.Left - (int)e.PageSettings.HardMarginX, e.PageBounds.Top - (int)e.PageSettings.HardMarginY, e.PageBounds.Width, e.PageBounds.Height); // Draw a white background for the report e.Graphics.FillRectangle(Brushes.White, adjustedRect); // Draw the report content e.Graphics.DrawImage(pageMetaFile, adjustedRect); // Prepare for next page. Make sure we haven't hit the end. _currentPage++; e.HasMorePages = _currentPage < _pages.Count; } } protected override void OnQueryPageSettings(QueryPageSettingsEventArgs e) { e.PageSettings = (PageSettings)PrinterSettings.DefaultPageSettings.Clone(); } } 
+4
source share

Source: https://habr.com/ru/post/1489764/


All Articles