0
我試圖打印服務器報告,而不使用C#預覽。該報告在WidowsXP中正常打印,但在Windows 7和Windows 10中以縮放視圖打印。下面是我的代碼。打印服務器報告沒有預覽顯示縮放報告
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
namespace Dahlawi.ManPower.Recruiting.Forms
{
public partial class FrmReportViewer1 : Form
{
List<Metafile> m_ReportPages = new List<Metafile>();
int m_ReportPageIndex = 0;
public FrmReportViewer1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
PrintDocument objPrintDoc = new PrintDocument();
objPrintDoc.PrintPage += PrintPageHandler;
PrintDialog objPrintDiag = new PrintDialog();
objPrintDiag.Document = objPrintDoc;
DialogResult objDiagResult = default(DialogResult);
objDiagResult = objPrintDiag.ShowDialog();
if (objDiagResult == DialogResult.OK)
{
objPrintDoc.PrinterSettings = objPrintDiag.PrinterSettings;
this.m_ReportPages = new List<Metafile>();
this.m_ReportPageIndex = 0;
this.reportViewer.ShowCredentialPrompts = false;
this.reportViewer.ServerReport.ReportServerCredentials.NetworkCredentials = new System.Net.NetworkCredential("USER", "PASSWORD", "DOMAIN");
this.reportViewer.ServerReport.ReportServerUrl = new Uri("http://SERVER/ReportServer");
this.reportViewer.ServerReport.ReportPath = "/DMR/Candidate_Information";
ReportParameter[] reportParameters = new ReportParameter[] { new ReportParameter("CandidateId", "16744") };
reportParameters[0].Visible = false;
this.reportViewer.ServerReport.SetParameters(reportParameters);
this.reportViewer.RefreshReport();
string deviceInfo = "<DeviceInfo>" + "<OutputFormat>emf</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.2in</MarginTop>" + " <MarginLeft>0.5in</MarginLeft>" + " <MarginRight>0.5in</MarginRight>" + " <MarginBottom>0.2in</MarginBottom>" + "</DeviceInfo>";
Warning[] objWarnings = null;
string[] sStreamIDs = null;
string sMimeType = "";
string sEncoding = "";
string sFilenameExtension = "";
byte[] renderedPage = null;
renderedPage = this.reportViewer.ServerReport.Render("Image", deviceInfo, out sMimeType, out sEncoding, out sFilenameExtension, out sStreamIDs, out objWarnings);
this.m_ReportPages.Add(new Metafile(new MemoryStream(renderedPage)));
foreach (string sStreamId in sStreamIDs)
{
renderedPage = this.reportViewer.ServerReport.RenderStream("Image", sStreamId, deviceInfo, out sMimeType, out sEncoding);
this.m_ReportPages.Add(new Metafile(new MemoryStream(renderedPage)));
}
objPrintDoc.Print();
objPrintDoc = null;
}
}
private void PrintPageHandler(object sender, PrintPageEventArgs e)
{
if (this.m_ReportPageIndex < this.m_ReportPages.Count)
{
Metafile imgPage = this.m_ReportPages[this.m_ReportPageIndex];
this.m_ReportPageIndex += 1;
e.Graphics.DrawImage(imgPage, 0, 0, imgPage.Width, imgPage.Height);
e.HasMorePages = this.m_ReportPageIndex < this.m_ReportPages.Count;
}
}
}
}
當我打印使用上述在WindowsXP它打印這樣Proper Print
但是,當我在Windows 7或Windows 10運行相同的代碼,它打印這樣Zoomed Print
代碼的報告請幫我在Windows 7/Windows 10上運行此代碼。如果需要,我可以提供更多詳細信息。