我有一个c#代码,可以将报告呈现为pdf格式。
Random rand = new Random();
num = rand.Next(1111, 999999);
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
String deviceInf = "<DeviceInfo><PageHeight>8.27in</PageHeight><PageWidth>11.69in</PageWidth><MarginTop>0in</MarginTop><MarginBottom>0in</MarginBottom><MarginLeft>0in</MarginLeft><MarginRight>0in</MarginRight></DeviceInfo>";
byte[] bytes = reportViewer1.LocalReport.Render
(
"PDF", deviceInf, out mimeType, out encoding,
out extension,
out streamids, out warnings);
var folderPath = "D:\\ICard\\STAFFPDF\\";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
FileStream fs = new FileStream(@"D:\ICard\STAFFPDF\" + num + ".pdf", FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
this.reportViewer1.Refresh();
fs.Close();
我想要做的是将pdf保存为镜像形式,因为pdf需要打印为镜像,有什么办法可以实现吗?
答案 0 :(得分:1)
试试这段代码。来源是here。
private string ExportReport()
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
ReportParameterInfoCollection pInfo = reportViewer1.ServerReport.GetParameters();
string filenameParams = "";
byte[] bytes;
if (reportViewer1.ProcessingMode == ProcessingMode.Local)
{
bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType,
out encoding, out filenameExtension, out streamids, out warnings);
}
else
{
bytes = reportViewer1.ServerReport.Render("PDF", null, out mimeType,
out encoding, out filenameExtension, out streamids, out warnings);
}
string filename = Path.Combine(Path.GetTempPath(), filenameParams + ".pdf");
using (FileStream fs = new FileStream(filename, FileMode.Create))
{ fs.Write(bytes, 0, bytes.Length); }
return filename;
}