iTextSharp for Phrase Doc: A Complete Information
Introduction
Greetings, readers! Welcome to our in-depth information to iTextSharp for Phrase paperwork. Whether or not you are a seasoned developer or simply getting began, this text will offer you a complete understanding of this highly effective software for creating, modifying, and manipulating Phrase paperwork.
iTextSharp is a extremely regarded .NET library that empowers builders to programmatically work with Phrase paperwork. With an unlimited array of options, iTextSharp permits you to carry out numerous operations, together with creating new paperwork, including textual content and pictures, modifying web page structure, and far more.
Making a Phrase Doc with iTextSharp
1. Making a New Doc
Start by creating a brand new occasion of the Doc class. This class serves as the muse on your Phrase doc.
Doc doc = new Doc();
2. Setting Web page Margins and Orientation
To customise web page margins and orientation, use the SetMargins and SetPageSize strategies.
doc.SetMargins(36, 72, 36, 72);
doc.SetPageSize(PageSize.A4);
Modifying a Phrase Doc with iTextSharp
1. Including Textual content and Formatting
Use the Add technique to insert textual content into the doc. It’s also possible to apply formatting reminiscent of daring, italic, and font measurement utilizing the SetFont and SetStyle strategies.
doc.Add(new Paragraph("It is a pattern textual content."));
doc.Add(new Paragraph("This textual content is daring and italic.")
.SetBold(true)
.SetItalic(true));
2. Including Photographs
To embed a picture into the doc, use the Add technique with the Picture object.
Picture picture = Picture.GetInstance("sample_image.png");
doc.Add(picture);
Manipulating Phrase Doc Content material
1. Including Web page Break
Insert a web page break within the doc utilizing the Add technique with the Paragraph object having the KeepTogether property set to true.
doc.Add(new Paragraph("")
.SetKeepTogether(true));
2. Including Desk of Contents
Producing a desk of contents mechanically is made straightforward with the CreateBookmark and AddOutline strategies.
doc.CreateBookmark("toc");
doc.AddOutline("Desk of Contents", "toc");
Utilizing iTextSharp with PDF
1. Convert Phrase to PDF
With iTextSharp, you possibly can seamlessly convert Phrase paperwork to PDF format.
PdfWriter author = PdfWriter.GetInstance(doc, new FileStream("output.pdf", FileMode.Create));
doc.Shut();
2. Convert PDF to Phrase
iTextSharp additionally allows you to carry out the reverse operation, changing PDF paperwork to Phrase format.
Doc wordDocument = new Doc();
PdfReader reader = new PdfReader("enter.pdf");
for (int i = 1; i <= reader.NumberOfPages; i++) {
Picture picture = reader.GetPageImage(i, 1, true);
doc.Add(picture);
}
Desk: Comparability of iTextSharp and Different Phrase Processing Libraries
| Function | iTextSharp | Aspose.Phrases | Spire.Doc |
|---|---|---|---|
| Cross-platform assist | Sure | Sure | Sure |
| Helps DOCX, DOC, and RTF | Sure | Sure | Sure |
| Web page structure manipulation | Sure | Sure | Sure |
| Desk and picture dealing with | Sure | Sure | Sure |
| PDF conversion | Sure | Sure | Sure |
Conclusion
iTextSharp for Phrase doc supplies an unparalleled degree of management and suppleness for creating, modifying, and manipulating Phrase paperwork programmatically. Whether or not you are seeking to automate doc creation, extract information, or convert paperwork between codecs, iTextSharp is an indispensable software.
For additional exploration of iTextSharp’s capabilities, we suggest testing the next articles:
FAQ about iTextSharp for Phrase Paperwork
1. What’s iTextSharp?
iTextSharp is a well-liked open-source library for creating, manipulating, and changing PDF and different doc codecs in C#.
2. Can I take advantage of iTextSharp to create Phrase paperwork?
No, iTextSharp doesn’t assist Phrase doc (DOCX) creation or manipulation. It’s primarily targeted on PDF doc dealing with.
3. What’s the finest different to iTextSharp for Phrase doc processing?
Aspose.Phrases is an industry-leading industrial library that gives complete assist for Phrase paperwork, permitting you to create, edit, convert, and carry out a variety of operations.
4. Can I take advantage of iTextSharp to transform Phrase paperwork to PDF?
Whereas iTextSharp doesn’t provide direct assist for Phrase doc conversion, you need to use third-party bridges or converters to attain this performance. For instance, you need to use Aspose.Phrases to transform Phrase paperwork to PDF after which use iTextSharp to govern the ensuing PDF.
5. Is iTextSharp free to make use of?
Sure, iTextSharp is free and open-source for each industrial and non-commercial use.
6. What are some great benefits of utilizing iTextSharp?
iTextSharp is a strong library that gives a variety of options for PDF dealing with, together with:
- Creation and manipulation of PDF paperwork
- Assist for PDF/A and different PDF requirements
- Encryption and digital signatures
- Content material extraction and evaluation
7. What are the disadvantages of utilizing iTextSharp?
- Doesn’t assist direct Phrase doc processing
- Restricted assist for some superior PDF options
- Could require extra third-party parts for sure functionalities
8. Are there any options to iTextSharp for .NET?
Sure, there are a number of different libraries you possibly can think about:
- Aspose.Phrases (industrial)
- Spire.Doc (industrial)
- ClosedXML (open supply)
- DocumentFormat.OpenXML (a part of Microsoft Workplace Open XML SDK)
9. How can I get began with iTextSharp?
You possibly can obtain the iTextSharp library from its official web site and discover in depth documentation and tutorials on-line.
10. The place can I discover assist for iTextSharp?
Yow will discover assist for iTextSharp by the library’s official documentation, on-line boards, and the iTextSharp neighborhood.