c# - Error while opening PDF -
i getting "failed load pdf document" in chrome , "the file damaged , not repaired" in ie few files.
the code below:
pdfsteramer:
if (pdf != null) { response.contenttype = "application/pdf"; response.addheader("content-type", "application/pdf"); response.addheader("content-disposition", "inline"); pdf.renderer.render(pdf, response.outputstream); response.flush(); }
and in render class:
using (filestream fs = new filestream(this._parentdocument.document.fullname, filemode.open, fileaccess.read)) { byte[] buffer = new byte[buffersize]; fs.read(buffer, 0, buffersize); using (stringreader reader = new stringreader(system.text.asciiencoding.ascii.getstring(buffer))) { decoder decoder = new uudecoder(stream, ""); string data; while ((data = reader.readline()) != null) { decoder.decodeline(data); } } }
and in decodeline below:
public override bool decodeline(string line) { try { byte[] data = encoding.utf8.getbytes(line); //byte[] data = uudecode(line); outstream.write(data, 0, data.length); } catch (exception ex) { } return false; }
below throws in firefox:
and on adobe reader:
if pdf stored in physical file, don't need use intermediary streams @ all, use transmitfile method has benefit of not using .net memory (in cases):
response.addheader("content-type", "application/pdf"); response.addheader("content-disposition", "inline"); response.transmitfile(your pdf path);
Comments
Post a Comment