Reputation: 12273
I have used itextsharp for PDF documents and now I need to create and add a text to a Word document(I'm using OpenXml SDK) so I would like to know what classes and objects are used here to add a paragraph or to set the alingment and indentation or to set the basefont and size of font. For example, this is my code for creating PDF using iTextSharp and now I want to translate it to create Word:
Document document = new Document(iTextSharp.text.PageSize.A4, 40, 40, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFile.FileName, FileMode.Create));
document.Open();
document.NewPage();
Paragraph title = new Paragraph("aaa",titleFont);
title.Alignment = Element.ALIGN_CENTER;
document.Add(title);
document.Add(Chunk.NEWLINE);
Paragraph p1 = new Paragraph("",Font11);
p1.IndentationLeft = 20f;
document.Add(p1);
Upvotes: 0
Views: 2267
Reputation: 12273
This is have I done it with DocX.dll:
var document = DocX.Create(wordFile.FileName);
Novacode.Paragraph title = document.InsertParagraph("AAA", false, titleFormat);
title.Alignment = Alignment.center;
document.InsertParagraph(Environment.NewLine);
document.Save();
Process.Start("WINWORD.exe", wordFile.FileName);
Upvotes: 0
Reputation: 25693
The best way to discover the things you ask about is to download the Open XML SDK Productivity Tool from Microsoft's site. Create a small, sample document in Word (as a user), save it, close it, then open it in the Productivity Tool. That can show you both the underlying XML as well as standard code for generating the document. That way you can see what objects are used and how they're put together.
Upvotes: 2