Last post May 15, 2019 04:59 PM by markdirtyboy
May 14, 2019 05:01 PM|markdirtyboy|LINK
I am using a .docx to make a pdf after that it is supposed to open on the client computer but it opens on the server, how can I solve this?
here is the code I'm using
Words w = new Words();
var word = new Word.Application();
var Documento = new Word.Document();
Documento = word.Documents.Open(@"\\192.168.10.21\j\Docs\Solicitud de vacaciones.docx");
Documento.Bookmarks["Numero"].Range.Text = v.ndias;
Documento.Bookmarks["Dias"].Range.Text = v.dias;
Documento.Bookmarks["Año"].Range.Text = v.año;
Documento.Bookmarks["Nombre"].Range.Text = v.Nombre;
Documento.Bookmarks["Fecha"].Range.Text = DateTime.Today.ToShortDateString();
Documento.Bookmarks["Fecha1"].Range.Text = DateTime.Today.ToShortDateString();
Documento.Bookmarks["Fecha2"].Range.Text = DateTime.Today.ToShortDateString();
word.Visible = false;
w.wordDocument = Documento;
w.wordDocument.ExportAsFixedFormat("Solicitud de Vaciones de " + v.Nombre + ".pdf", Word.WdExportFormat.wdExportFormatPDF, false, Word.WdExportOptimizeFor.wdExportOptimizeForPrint);
May 14, 2019 05:08 PM|PatriceSc|LINK
It is sometimes confusing for newcomers to web development as most often your machine is both the server and the client which can give a false impression about what happens where. Generally speaking all your C# code runs on the server side.
You'll have to use something such as https://forums.asp.net/t/1835679.aspx?save+file+dialog+to+download+PDF+file+C+ to send the PDF file content to the browser and
maybe trigger a download dialog so the user can save or open the file.
Not directly related but using Word on a server is not supported.
May 15, 2019 08:26 AM|Wei Zhang|LINK
According to your description, if you want to realize the function for .docx to pdf and open it on client computer. I think you should firstly upload a .dox file from client,then you could build a pdf on client. Then some on client side could download it
and open on client side.
So I think you only need to download file as pdf in client.Here is the code, I hope it could help you.
protected void Button2_Click(object sender, EventArgs e)
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=xx.mp4");
Here is the link I hope it could help you.
May 15, 2019 04:59 PM|markdirtyboy|LINK
Thanks for your replay,
I decided to use your answer when I made the .pdf I save it and I use the path to download the pdf as you mentioned