

#PDFWRITER GETINSTANCE PDF#
Now it’s time to get some visuals into the PDF file. If for instance you want to generate TeX-documents as well, you could write a package: m.ĭfWriter.getInstance(document, new FileOutputStream(“filename.pdf”))
#PDFWRITER GETINSTANCE PORTABLE#
For the moment there are two possibilities: you can use .PdfWriter to generate documents in the Portable Document Format, or you can use .HtmlWriter to generate documents in HTML. All writers should be derived from the abstract class.

Once our document is created, we can create one or more instances of writers that listen to this document. Further options are: A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA and FLSE. PageSize.A0 automatically assigns the right values for a A0 size to the document instance. So also possible is for example:ĭocument document = new Document(PageSize.A0) The second constructor calls the third one, with 36 as value for each margin. The first constructor calls the second one, with PageSize.A4 as parameter. Public Document(Rectangle pageSize, int marginLeft, int marginRight, int marginTop, int marginBottom) PageSize is a new rectangle instance which is going to contain some properties for the document instance about for example: size and color. The is a check to see if the creation of the PDF file is actually called after running your application. Rectangle pageSize = new Rectangle(0,0,2382,3369) ĭocument document = new Document(pageSize) Now you need to import the iText libraries: Just start your class as learned in the Java assignments:
#PDFWRITER GETINSTANCE CODE#
After the installation of your Java editor, JSDK’s and setting the right class path to the iText.jar file you can start with your code in Java to create a PDF file.

Write(ms.GetBuffer(), 0, ms.GetBuffer().Length) SetCacheability(HttpCacheability.NoCache) ("content-disposition", "attachment filename= " + fileName + "") StreamReader reader = new StreamReader(stream) įoreach (IElement element in HTMLWorker.ParseToList(reader, styles)) MemoryStream stream = new MemoryStream(byteArray) Styles.LoadTagStyle("th", HtmlTags.ALIGN, HtmlTags.ALIGN_CENTER) īyte byteArray = (html.ToString()) Styles.LoadTagStyle(HtmlTags.TABLE, HtmlTags.BORDERWIDTH, "0.3") Styles.LoadTagStyle(HtmlTags.TABLE, HtmlTags.ALIGN, HtmlTags.ALIGN_TOP) Styles.LoadTagStyle("p", "face", "Arial") Styles.LoadTagStyle("td", "face", "Arial") Styles.LoadTagStyle("td", "size", "8px") Styles.LoadTagStyle("span", "face", "Arial") Styles.LoadTagStyle("span", "size", "8px") Styles.LoadTagStyle("th", "face", "Arial") Styles.LoadTagStyle("th", "text-align","center") Styles.LoadTagStyle("th", "size", "12px") HTMLWorker htmlWorker = new HTMLWorker(pdfDocument)

PdfDocument.Add(new ("Title of the PDF" + "\n\n", PdfWriter writer = PdfWriter.GetInstance(pdfDocument, ms) rect = PageSize.A4 ĭocument pdfDocument = new Document(rect, 10f, 10f, 50f, 0f) Using iTextSharp using iTextSharp.text using using using You need to add the iTextSharp.dll to your solution and add Namespace to your webpart. In my case i am preparing one dynamic string builder which have fully loaded content and exporting the same to Pdf by using the iTextSharp. Below example is used to export the HTML to PDF.
