Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
in Outlook if we forward or create a new mail than the pdf file is converting with red colour fonts with underlines ..we use asp dot net 4.7.2 desktop application..We have customize button in MS outlook through this user can send email as PDF files to another application

What I have tried:

public static string DocConvertionUrl = "https://xxx.com/doc2pdf";
        public static string ConvertWord(string docFilePath)
        {
            string pdfFilePath;
            try
            {
                // Load the DOC document using Aspose.Words
                using (WebClient client = new WebClient())
                {
                    var bytes = File.ReadAllBytes(docFilePath);
 
                    byte[] responsebytes = client.UploadData(DocConvertionUrl, bytes);
                    pdfFilePath = docFilePath.Replace(".doc", ".pdf");
 
 
                    using (var fs = new FileStream(pdfFilePath, FileMode.Create, FileAccess.Write))
                    {
                        fs.Write(responsebytes, 0, responsebytes.Length);
                    }
                }
                CloseWord();
                DeleteWord(docFilePath);
                return pdfFilePath;
            }
            catch (System.Exception ex)
            {
                // Handle any exceptions here
                //Helper.ErrorMessage = ex.Message + ex.StackTrace;
 
                Console.WriteLine("Error converting DOC to PDF: " + ex.Message);
                return null;
 
            }
        }
Posted
Comments
Dave Kreskowiak 20-Mar-24 12:50pm    
The code you posted just uploads a file to a webserver. It doesn't do any conversion at all. The problem is going to be in the server-side code, not the code you posted here.
Thirumadhi T Johnson 21-Mar-24 0:27am    
Hi Dave , This is only server side code ..this not a client side code...
public static string DocConvertionUrl = "https://xxx.com/doc2pdf"; is this code is causing an issue
Thirumadhi T Johnson 21-Mar-24 2:03am    
and this is desktop based application
Thirumadhi T Johnson 21-Mar-24 5:14am    
Yes Dave you are write there is a client side code with this
public static string DocConvertionUrl = "https://xxx.com/doc2pdf";


it is deployed in Server as below

<%@ Page Language="C#"%><%
                            var ins = Request.InputStream;

                            var loadOptions = new Aspose.Words.Loading.LoadOptions { LoadFormat = Aspose.Words.LoadFormat.Auto };
                            var pdfDocument = new Aspose.Words.Document(ins, loadOptions);

                            pdfDocument.Save(Response,"file.pdf", Aspose.Words.ContentDisposition.Attachment, new Aspose.Words.Saving.PdfSaveOptions() );
%>
Dave Kreskowiak 21-Mar-24 9:17am    
So you're sending a Word document file to a web service somewhere and it's returning a PDF file? So who controls the web service? If it's not returning a document correctly, you're going to have to contact the people running that service for support.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900