Click here to Skip to main content
15,914,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a dropdownlist that has PDF and DOC
I have made it work to save to PDF , but when trying to save to Word i get
File Conversion 'Select the enconding that makes your document readable Text Encoding' there i can select between Windows (Default) Ms-DOS and Other encoding

Preview looks as
%PDF-1.4
%AaaIO
1 0 obj
<<type/XObject/Subtyp/Image/Width 127/height

My code look as following i dont now if i can save to Word also using iTextSharper, maybe then i should add UTF-9 somewere?

C#
protected void DownloadCv_Click(object sender, ImageClickEventArgs e)
        {
            {
                        string sDirPath = Server.MapPath("~/PDF_WORD/Docs");



                        var ObjSearchDir = new DirectoryInfo(sDirPath);
                        if (!ObjSearchDir.Exists)
                        {
                            ObjSearchDir.Create();
                        }
                        string strFileName =
                            HttpContext.Current.Server.MapPath("~/PDF_WORD/Docs/Test." +
                                                               DropDownListDownloadCv0.SelectedValue.ToString() +
                                                               "");
                        var objfileinfo = new FileInfo(strFileName);
                        // step 1: creation of a document-object
                        var document = new Document(PageSize.A4);



                        if (objfileinfo.Exists)
                        {
                            File.Delete(strFileName);
                            PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));
                        }
                        else
                            PdfWriter.GetInstance(document, new FileStream(strFileName, FileMode.Create));



                        var sb = new StringBuilder();
                        var sw = new StringWriter(sb);

                        document.Open();
                        var hTextWriter = new HtmlTextWriter(sw);
                        

                        String strHtml1 = sw.ToString();

                        var hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
                        
                        hw.Parse(new StringReader(strHtml1));
                        document.Close();

                    }
                }

            }
        }
Posted

1 solution

According to that preview, you're trying to load a PDF document as if it were a Word file. Sorry, not going to work.
 
Share this answer
 
Comments
Kurac1 23-Apr-13 15:16pm    
Alright so i should have that code only for pdf? and write another for saving to word?
Dave Kreskowiak 23-Apr-13 15:29pm    
Uhhh...DUH! Come on...when has writing one document ever resulted in 2 files of completely different file formats??
Kurac1 23-Apr-13 15:42pm    
Okey

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