Chris Hansen
Chris Hansen

Reputation: 103

iTextSharp to Word

I am using iTextSharp in my MVC application to create a .pdf file, but is there a way to convert it to a .doc file?

public ActionResult Download(int? Id)
    {
        string FileName = "Test";

        var FilePath = Path.Combine(Path.GetTempPath(), "Temp.pdf");

        Document UserPDF = new Document();
        PdfWriter.GetInstance(UserPDF, new FileStream(FilePath, FileMode.Create));

        CreateCv(UserPDF); // This is where the PDF is created

        var fs = new FileStream(FilePath, FileMode.Open);
        var Bytes = new byte[fs.Length];
        fs.Read(Bytes, 0, (int)fs.Length);
        fs.Close();

        return File(Bytes, "application/pdf", FileName + ".pdf");
    }

Upvotes: 0

Views: 7774

Answers (1)

Brad C
Brad C

Reputation: 2982

To put it simply, no. There is no way to convert it to a DOC file using iTextSharp. It only supports the reading and generating of PDF files.

Converting PDF to DOC is possible by using some other third party libraries but there is no solid way of doing it (and preserving formatting / whitespace) at the moment. If you search the web, people suggest creating an image from the PDF and then appending the image to the end of a blank DOC file (which is a major hack).

Upvotes: 3

Related Questions