locked
How to open a pdf on client RRS feed

  • Question

  • User-1634117515 posted

    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);
            w.wordDocument.Close(Word.WdSaveOptions.wdDoNotSaveChanges);

    Tuesday, May 14, 2019 5:01 PM

Answers

  • User753101303 posted

    Hi,

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2019 5:08 PM
  • User-1174608757 posted

    Hi markdirtyboy,

    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");
                Response.TransmitFile(Server.MapPath(@"~/xx.pdf"));
                Response.End();
    
            }

    Here is the link I hope it could help you.

    https://forums.asp.net/t/2102987.aspx?Download+file+from+current+web+form+

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 15, 2019 8:26 AM

All replies

  • User753101303 posted

    Hi,

    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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2019 5:08 PM
  • User-1174608757 posted

    Hi markdirtyboy,

    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");
                Response.TransmitFile(Server.MapPath(@"~/xx.pdf"));
                Response.End();
    
            }

    Here is the link I hope it could help you.

    https://forums.asp.net/t/2102987.aspx?Download+file+from+current+web+form+

    Best Regards

    Wei

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 15, 2019 8:26 AM
  • User-1634117515 posted

    Hi,

    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 

    Wednesday, May 15, 2019 4:59 PM