Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript silent printing sometimes prints blank or nothing

Guest
Jan 05, 2018 Jan 05, 2018

HELP!

We use a third party tool, Gnostice to take a PDF report created by SQL Report Services and embed the Adobe JavaScript necessary to automatically print the PDF when it is opened in a browser window.  This functionality has been working without flaw for many years and hasn't changed.  Recently, our customers started reporting that they now sometimes get blank pages or nothing prints at all. The code we use to render the PDF to the browser window is at the bottom of the post.

We thought it might have been our upgrade from Adobe Reader 11 to Adobe DC; however, we downgraded and are still having the problem.  Has anyone else experienced this issue?  If so, what steps might we be able to take to troubleshoot and/or resolve the issue.

Any assistance would be appreciated.

RENDER C# CODE BELOW

public void RenderPDF(byte[] buffer, string reportName, string contentType)

{

     var s = new MemoryStream(buffer, true);

     PDFDocument doc = null;

     try

     {

          var printer = "\\\\AL-FILE-PRINT\\QA Dell";

          var pdfJavascript = new StringBuilder();

          doc = new PDFDocument("C454-055C-9402-AD24-C3D8-95FD-6A50-3C77");

          s.Position = 0;

          doc.Load(s);

          pdfJavascript.Append("this.disclosed = true; var mymessage = new Array(); ");

          pdfJavascript.Append("try { ");

          pdfJavascript.Append(" var objDoc = this; ");

          pdfJavascript.Append(" var objPrintParams = objDoc.getPrintParams(); ");

          pdfJavascript.Append(" objPrintParams.interactive = objPrintParams.constants.interactionLevel.silent; ");

          pdfJavascript.Append($" objPrintParams.printerName = '{printer.Replace("\\", "\\\\")}'; ");

          pdfJavascript.Append(" objDoc.print(objPrintParams); ");

          pdfJavascript.Append("} ");

          pdfJavascript.Append("catch(e) { ");

          pdfJavascript.Append(" app.alert('There was an error printing'); ");

          pdfJavascript.Append(" app.alert(e); ");

          pdfJavascript.Append("} ");

          doc.AddOpenActionJavaScript(pdfJavascript.ToString());

          s = new MemoryStream { Position = 0 };

          doc.Save(s);

          Response.ClearHeaders();

          Response.ClearContent();

          Response.BufferOutput = true;

          Response.AddHeader("Content-Length", s.Length.ToString());

          Response.AddHeader("Content-Disposition", "inline; filename=" + reportName);

          Response.AddHeader("Accept-Ranges", "bytes");

          Response.ContentType = contentType;

          var dataLengthToRead = s.Length;

          var blockSize = dataLengthToRead >= 5000 ? 5000 : Convert.ToInt32(dataLengthToRead);

          var b = new byte[Convert.ToInt32(dataLengthToRead - 1) + 2];

          s.Position = 0;

          while (dataLengthToRead > 0 && Response.IsClientConnected)

          {

               var lengthRead = s.Read(b, 0, blockSize);

               Response.OutputStream.Write(b, 0, lengthRead);

               dataLengthToRead = dataLengthToRead - lengthRead;

          }

          HttpContext.Current.ApplicationInstance.CompleteRequest();

          Response.Flush();

          Response.Close();

     }

     catch (Exception ex)

     {

          MessageLabel.Text = $"Print Errro: {ex.Message}";

     }

     finally

     {

          s?.Dispose();

          doc?.Dispose();

     }

}

TOPICS
Acrobat SDK and JavaScript
776
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation