I am looking to generate an RDLC report on the client's machine without having to preview it. Since I cannot use the ReportViewer print button due to restrictions with ActiveX installation, I have opted to utilize ITextSharp to convert the rendered LocalReport into a PDF and incorporate JavaScript for printing.
While debugging, I can confirm that the PDF is successfully created with 2 pages and everything appears to be in order. However, despite no errors being reported and the function exiting properly, the document does not print. I'm unsure of what I might be overlooking or doing incorrectly.
Below is the snippet of my code:
string jsPrint = "var pp = this.getPrintParams();pp.interactive= pp.constants.interactionLevel.silent;this.print(pp);";
byte[] bytes = report.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
using (MemoryStream ms = new MemoryStream())
{
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, ms);
doc.SetPageSize(PageSize.A4);
doc.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
PdfReader reader = new PdfReader(bytes);
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
doc.SetPageSize(PageSize.A4);
doc.NewPage();
page = writer.GetImportedPage(reader, i);
cb.AddTemplate(page, 0, 0);
}
PdfAction jAction = PdfAction.JavaScript(jsPrint, writer);
writer.AddJavaScript(jAction);
doc.Close();
}
Any insights would be greatly appreciated. Thank you.