MVC에서 rdlc 보고서를 사용하고 있는데, Visual Studio에서 실행할 때 인쇄 작업이 완벽하게 작동하지만 같은 컴퓨터에 설정된 iis에 게시하면 인쇄 작업이 일어나지 않습니다. 그러나 보고서를 pdf로 반환하면 보고서가 javascript를 사용하여 파일을 인쇄 할 수 있지만 실제로 보고서를 표시하고 싶지는 않지만 서버에서 인쇄하고 싶습니다. 미리 도움을 주셔서 감사합니다.
public ActionResult GenerateOrder()
{
try
{
LocalReport report = new LocalReport();
report.ReportPath = (Server.MapPath("~/Reports/Report1.rdlc"));
Export(report);
Print();
}
catch (Exception Ex)
{
}
return View();
}
private Stream CreateStream(string name,
string fileNameExtension, Encoding encoding,
string mimeType, bool willSeek)
{
Stream stream = new MemoryStream();
m_streams.Add(stream);
return stream;
}
private void Export(LocalReport report)
{
string deviceInfo =
@"<DeviceInfo>
<OutputFormat>EMF</OutputFormat>
<PageWidth>8.5in</PageWidth>
<PageHeight>11in</PageHeight>
<MarginTop>0.25in</MarginTop>
<MarginLeft>0.25in</MarginLeft>
<MarginRight>0.25in</MarginRight>
<MarginBottom>0.25in</MarginBottom>
</DeviceInfo>";
Warning[] warnings;
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, CreateStream,
out warnings);
foreach (Stream stream in m_streams)
stream.Position = 0;
}
private int m_currentPageIndex;
private IList<Stream> m_streams;
private void PrintPage(object sender, PrintPageEventArgs ev)
{
try
{
Metafile pageImage = new
Metafile(m_streams[m_currentPageIndex]);
// Adjust rectangular area with printer margins.
Rectangle adjustedRect = new Rectangle(
ev.PageBounds.Left - (int)ev.PageSettings.HardMarginX,
ev.PageBounds.Top - (int)ev.PageSettings.HardMarginY,
ev.PageBounds.Width,
ev.PageBounds.Height);
// Draw a white background for the report
ev.Graphics.FillRectangle(Brushes.White, adjustedRect);
// Draw the report content
ev.Graphics.DrawImage(pageImage, adjustedRect);
// Prepare for the next page. Make sure we haven't hit the end.
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
catch (Exception ex)
{
}
}
private void Print()
{
if (m_streams == null || m_streams.Count == 0)
throw new Exception("Error: no stream to print.");
PrintDocument printDoc = new PrintDocument();
if (!printDoc.PrinterSettings.IsValid)
{
throw new Exception("Error: cannot find the default printer.");
}
else
{
PrinterSettings pset = new PrinterSettings();
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
m_currentPageIndex = 0;
printDoc.PrinterSettings.PrinterName = pset.PrinterName;
printDoc.Print();
}
}
서버 자체에서 페이지를 인쇄하고 싶다고 생각합니다. 애플리케이션이 실행중인 ID를 확인하십시오 . 기본 계정으로 실행중인 경우 계정 또는 프린터 액세스 권한이 있는 다른 계정으로 변경하십시오 .
IIS로 이동합니다. (a) 먼저 앱에서 사용 중인 응용 프로그램 풀을 찾습니다. (b) 그런 다음 응용 프로그램 풀 세부 정보 로 이동 하여 사용 중인 ID를 찾습니다 . (c)이 ID를 프린터 액세스 권한이있는 사용자 / 다른 계정으로 변경합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다