c# - Create a PDF from retrieved data, and return the PDF to the browser WITHOUT a third party tool? -
ok, i'm trying take information database, , convert info pdf, without using third-party tool. i've googled this, , tried several different incarnations. closest i've gotten this:
[httpget, actionname("getthepdf")] public void createthefile() { response.buffer = true; response.clear(); response.clearcontent(); response.clearheaders(); string mystring = "lorem ipsum dolor sit amet, consectetur adipiscing elit. nulla ac eleifend nunc, eget consequat arcu."; byte[] bytes = system.text.encoding.utf8.getbytes(mystring); response.contenttype = "application/octet-stream"; response.addheader("accept-ranges", "bytes"); response.addheader("content-disposition", "inline; filename=testdoc_1.pdf"); response.addheader("content-length", mystring.length.tostring()); response.binarywrite(bytes); response.flush(); }
which doesn't work on https. "creates" pdf (or, more correctly, file .pdf extension), whenever try open in adobe reader, get:
adobe reader not open 'testdoc_1.pdf' because either not supported file type or because file has been damaged...
when try open in browser (chrome, in case), "failed load pdf document".
what's odd (and function of software) if change desired file type .doc, puts unformatted text in .doc file can open word.
the company wants pdf end user can print or save local machine, i'm trying figure out how give them want. if isn't possible, may have see if can them settle .doc file.
at point, doesn't have pretty, has work.
any tips or suggestions appreciated.
if want create pdf, has conform pdf specification (available fee iso: pdf specification). it's not plain text pdf extension. of course write own implementation, if absolutely cannot use third party library, advice against that. it's lot of work, , others have done better could.
Comments
Post a Comment