Click here to Skip to main content
15,905,967 members

Comments by Camects (Top 2 by date)

Camects 15-Jan-16 4:56am View    
You may (or may not) know this but I'd like to point out that the code that you posted in the below comments is not actually creating a DOC file:

Response.AddHeader("content-disposition", "attachment;filename=" + title + ".doc");
Response.Charset = "";
Response.ContentType = "application/ms-word";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvExport.RenderControl(hw);

string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

What this does is it takes a HTML representation of a GridView and saves it as a file with a DOC extension. This is a sort of a workaround because MS Word is able to read and display that HTML file however when opening this file it will throw a warning that says that a file's format and extension are not the same. After you re-save it with MS Word then it will become a "real" DOC file.
Now depending on the situation this may not be an ideal solution, so as an alternative you can check out how to convert a HTML content into a Word document in C#.

Another alternative is this:
http://www.codeproject.com/Articles/91894/HTML-as-a-Source-for-a-DOCX-File
But note that this approach only works for MS Word. In other words the documents created by that approach will appear empty in any other Word application (except in MS Word).
Camects 14-Jan-16 4:58am View    
You can consider using this Word library for C#, for example like the:

var document1 = DocumentModel.Load("Sample1.pdf");
var table1 = (Table)document1.GetChildElements(true, ElementType.Table).First();

var document2 = DocumentModel.Load("Sample2.pdf");
var table2 = (Table)document2.GetChildElements(true, ElementType.Table).First();

var document = new DocumentModel();
document.Sections.Add(
   new Section(document,
       document.Import(table1, true),
       document.Import(table2, true)));

document.Save("Merged Table Samples.pdf");

Also the following link contains another example of reading a PDF file and extracting its text or table content in C#. Additionally if interested this sample shows how you can create a new PDF file in C# from scratch.