Created
December 1, 2013 06:19
-
-
Save satish860/7729201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using DocumentFormat.OpenXml.Packaging; | |
| using DocumentFormat.OpenXml.Wordprocessing; | |
| using iTextSharp; | |
| using iTextSharp.text.pdf; | |
| using System.IO; | |
| namespace PdfConvertorHack | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| WordprocessingDocument document = WordprocessingDocument.Open(@"E:\Programs\PdfConvertorHack\Hello.docx", false); | |
| var openXMLList = document.MainDocumentPart.Document.Body.ChildElements; | |
| foreach (var item in openXMLList) | |
| { | |
| if (item.GetType() == typeof(Table)) | |
| { | |
| Table table = item as Table; | |
| TableRow row = table.Descendants<TableRow>().First(); | |
| IEnumerable<TableCell> cells = row.Descendants<TableCell>(); | |
| int count = cells.Count(); | |
| iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(); | |
| PdfWriter writer = PdfWriter.GetInstance(pdfDocument, new FileStream(@"E:\Programs\PdfConvertorHack\Hello.pdf", FileMode.OpenOrCreate)); | |
| pdfDocument.Open(); | |
| PdfPTable pdftable = new PdfPTable(count); | |
| foreach (var cell in cells) | |
| { | |
| pdftable.AddCell(cell.InnerText); | |
| } | |
| pdfDocument.Add(pdftable); | |
| pdfDocument.Close(); | |
| Console.WriteLine("Found table in the document"); | |
| } | |
| } | |
| Console.ReadLine(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment