Esempio n. 1
0
        /// <summary>
        /// PDF Creator Helper With No Page Base (Don't want to write a page or report (header or footer)
        /// </summary>
        /// <param name="PageSize">Page Size - A4 is a default page size. Use Enum iTextSharp.text.PageSize</param>
        /// <param name="LandscapeMode">Do you want the pdf in landscape</param>
        /// <param name="MarginTop">Top Margin On The Page</param>
        /// <param name="MarginRight">Right Margin On The Page</param>
        /// <param name="MarginBottom">Bottom Margin On The Page</param>
        /// <param name="MarginLeft">Left Margin On The Page</param>
        /// <param name="PageEventHandler">A Page Event Class That Will Raise Any Events You Need</param>
        public PDFCreator(Rectangle PageSize,
                          bool LandscapeMode,
                          float MarginTop,
                          float MarginRight,
                          float MarginBottom,
                          float MarginLeft,
                          PageEventsBase PageEventHandler)
        {
            //create the instance of the ITextSharpDocument
            Doc = new Document(PageSize, MarginLeft, MarginRight, MarginTop, MarginBottom);

            //let's build the memory stream now
            Ms = new MemoryStream();

            //let's create the new writer and attach the document
            Writer = PdfWriter.GetInstance(Doc, Ms);

            //add the page events to my custom class
            if (PageEventHandler != null)
            {
                Writer.PageEvent = PageEventHandler;
            }

            //if you want the pdf in landscape now, then rotate it
            if (LandscapeMode)
            {
                Doc.SetPageSize(PageSize.Rotate());
            }

            //let's open the document so the developer can do whatever they wan't with it
            Doc.Open();
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor for when you want to read an existing file into a writer
        /// </summary>
        /// <param name="ReaderToBuild">Reader to load into the writer</param>
        /// <param name="PageEventHandler">Page events use</param>
        public PDFCreator(PdfReader ReaderToBuild, PageEventsBase PageEventHandler)
        {
            //add the document
            Doc = new Document(ReaderToBuild.GetPageSizeWithRotation(1));

            //let's build the memory stream now
            Ms = new MemoryStream();

            //add the writer
            Writer = PdfWriter.GetInstance(Doc, Ms);

            //do we have any page events?
            if (PageEventHandler != null)
            {
                Writer.PageEvent = PageEventHandler;
            }

            //open the doc
            Doc.Open();

            //go add the pages now
            for (var i = 1; i <= ReaderToBuild.NumberOfPages; i++)
            {
                //add a new page
                Doc.NewPage();

                //grab the base font
                var BaseFontToUse = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                //import the page
                var ImportedPage = Writer.GetImportedPage(ReaderToBuild, i);

                //grab the bytes
                var ContentByte = Writer.DirectContent;

                //go write the imported page
                ContentByte.AddTemplate(ImportedPage, 0, 0);
            }
        }