예제 #1
0
        /// <summary>
        /// Add a page containing a single image.  Set the page size to match the image size.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="imagePath"></param>
        private void AddPageWithImage(iTextSharp.text.Document doc, String imagePath)
        {
            // Read the image file
            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(imagePath));

            // Set the page size to the dimensions of the image BEFORE adding a new page to the document.
            // Pad the height a bit to leave room for the page header.
            float imageWidth = image.Width;
            float imageHeight = image.Height;
            doc.SetMargins(0, 0, 0, 0);
            doc.SetPageSize(new iTextSharp.text.Rectangle(imageWidth, imageHeight + 100));

            // Add a new page
            doc.NewPage();

            // The header at the top of the page is an anchor linked to by the table of contents.
            iTextSharp.text.Anchor contentsAnchor = new iTextSharp.text.Anchor("\nGRAPH\n\n", _largeFont);
            contentsAnchor.Name = "graph";

            // Add the anchor and image to the page
            this.AddParagraph(doc, iTextSharp.text.Element.ALIGN_CENTER, _largeFont, contentsAnchor);
            doc.Add(image);
            image = null;
        }
예제 #2
0
 /// <summary>
 /// Set margins and page size for the document
 /// </summary>
 /// <param name="doc"></param>
 private void SetStandardPageSize(iTextSharp.text.Document doc)
 {
     // Set margins and page size for the document
     doc.SetMargins(50, 50, 50, 50);
     // There are a huge number of possible page sizes, including such sizes as
     // EXECUTIVE, POSTCARD, LEDGER, LEGAL, LETTER_LANDSCAPE, and NOTE
     doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width,
         iTextSharp.text.PageSize.LETTER.Height));
 }
예제 #3
0
        /// <summary>
        /// This method consist settings of pdf file
        /// </summary>
        /// <param name="ms"></param>
        /// <param name="doc"></param>
        public void Settings(MemoryStream ms, iTextSharp.text.Document doc)
        {
            PdfWriter.GetInstance(doc, ms);
            iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4);

            doc.SetPageSize(rec);

            doc.SetMargins(0, 0, 0, 0);

            doc.Open();

            doc.NewPage();
        }