javascript - ASP.net copy PDF from server to client sources -
I am currently working on a system where I want to copy the PDF file from my server to the customer's sources Opening in a embed tag
So far, I have the following server code ...
[HttpGet ("printpdf") ] Public HttpResponse getPDF () {System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; Response.ClearContent (); Response.Clear (); reaction. Contact type = "application / pdf"; Response.AddHeader ("content-dispute", "attachment; file name = preview pdf;"); Response.TransmitFile ("preview.pdf"); Response.Flush (); Response.End (); Return feedback; } and it is called by the customer with extJS
Ext.define ('RibbonMenu View. Dialogues.Print ', expand:' Ext. Window. ', Mixes: {Control Disilator:' Ribbon menu .VibrationRibon.ControlControllDisbuser}}, Title: 'print preview', height: 800, width: 800 Layout: 'fit', constrained: right: item: [{xtype: 'component', autoEl: {tag: 'embed', type: 'application / pdf', src: Ext.Ajax.request ({url: / Printpdf ? ", Method:" GET ", success: function (feedback, options) {con Sole.log ("get pdf"); var pdf = response; console.log (pdf) returns pdf}, failure: function (feedback, opts) {console.log ("failed to get pdf") console.log ( Response.status;}}}}}}}; Obvisouly is not right now because the src attribute of my embed tag looks
Src = "id: 1; Xhr: [object xmlHttpRequest]; Header: [object object], options: [object object]; Async: True; Binary: Fotal; Timeout: 26; " So, what I expect to do is actually finding a way to copy a PDF from the server to the client's sources as just one PDF object is passing. .
Edit
One thing to mention is that this functionality is used for print preview, which allows users' Printing / hence it is brain, use This file copy for the recipient is a temporary copy whose page is present within the session, and only a printable user can see it.
Edit
I want to copy the PDF to sources somewhere in the file structure in the image which will allow me to create a difficult URL to point to the embedded tag.
You need to host a PDF on some public
In your server side code you are embedding the file content in response, but what you have to do:
Copy the file to public folder (i file Assuming I'm already in the file system but not publicly in the proper place).
var sourcePath = "c: //path/to/the/original/file.pdf"; Var targetpath = "relative / url / to / public / folder / file pdf"; FileSystem.CopyFile (sourcePath, Server.MapPath (targetPath)); and return the URL to the file in response
System Web. HTTPResponse response = System. Web. Hpptx Running response; Response.ClearContent (); Response.Clear (); reaction. Content type = "text / plain"; Response.Write (TargetPath); Response.Flush (); Response.End (); Return feedback;
Comments
Post a Comment