I have this code for printing the PDF Document from file stream (using PdfSharp Library):
private HttpResponseMessage PrintPdfDocument2(MemoryStream fileStream)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fileStream);
PdfSharp.Pdf.PdfDictionary dict = new PdfSharp.Pdf.PdfDictionary(document);
dict.Elements["/S"] = new PdfSharp.Pdf.PdfName("/JavaScript");
dict.Elements["/JS"] = new PdfSharp.Pdf.PdfString("this.print(true);\r");
document.Internals.AddObject(dict);
document.Internals.Catalog.Elements["/OpenAction"] = PdfSharp.Pdf.Advanced.PdfInternals.GetReference(dict);
var outputStream = new MemoryStream();
document.Save(outputStream);
result.Content = new ByteArrayContent(outputStream.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return result;
}
It work fine in chrome and i.e but not work in Firefox
Any idea for this problem????
Thanks u guys for reading!
I found s solution (by looking at pdf.js source code)
var dict = new PdfDictionary(document);
dict.Elements["/Type"] = new PdfName("/Action");
dict.Elements["/S"] = new PdfName("/Named");
dict.Elements["/N"] = new PdfName("/Print");
document.Internals.AddObject(dict);
document.Internals.Catalog.Elements["/OpenAction"] = PdfSharp.Pdf.Advanced.PdfInternals.GetReference(dict);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With