Пример #1
0
        /// <summary>
        /// Adjust image drawing area for both aspect ratio and content alignment
        /// </summary>
        /// <param name="ImageWidthPix">Image width in pixels.</param>
        /// <param name="ImageHeightPix">Image height in pixels.</param>
        /// <param name="DrawArea">Drawing area rectangle</param>
        /// <param name="Alignment">Content alignment.</param>
        /// <returns>Adjusted drawing area rectangle</returns>
        public static PdfRectangle ImageArea(
			Int32				ImageWidthPix,
			Int32				ImageHeightPix,
			PdfRectangle		DrawArea,
			ContentAlignment	Alignment
			)
        {
            return(ImageArea(ImageWidthPix, ImageHeightPix, DrawArea.Left, DrawArea.Bottom, DrawArea.Width, DrawArea.Height, Alignment));
        }
Пример #2
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="Rect">Source rectangle</param>
        public PdfRectangle(
			PdfRectangle Rect
			)
        {
            this.Left = Rect.Left;
            this.Bottom = Rect.Bottom;
            this.Right = Rect.Right;
            this.Top = Rect.Top;
            return;
        }
        /// <summary>
        /// PDF table style default constructor.
        /// </summary>
        /// <param name="Font">Font</param>
        public PdfTableStyle(
			PdfFont Font = null
			)
        {
            Alignment = ContentAlignment.TopLeft;
            BackgroundColor = Color.Empty;
            TextBoxLineBreakFactor = 0.5;
            TextBoxTextJustify = TextBoxJustify.Left;
            this.Font = Font;
            FontSize = 9.0;
            Margin = new PdfRectangle();
            ForegroundColor = Color.Black;
            TextDrawStyle = DrawStyle.Normal;
            return;
        }
Пример #4
0
        /// <summary>
        /// PDF X Object constructor
        /// </summary>
        /// <param name="Document">PDF document</param>
        /// <param name="Width">X Object width</param>
        /// <param name="Height">X Object height</param>
        public PdfXObject(
			PdfDocument		Document,
			Double			Width = 1.0,
			Double			Height = 1.0
			)
            : base(Document, "/XObject")
        {
            // create resource code
            ResourceCode = Document.GenerateResourceNumber('X');

            // add subtype to dictionary
            Dictionary.Add("/Subtype", "/Form");

            // set boundig box rectangle
            Rect = new PdfRectangle(0.0, 0.0, Width, Height);
            return;
        }
Пример #5
0
        /// <summary>
        /// PdfTable constructor.
        /// </summary>
        /// <param name="Page">Current PdfPage.</param>
        /// <param name="Contents">Current PdfContents.</param>
        /// <param name="Font">Table's default font.</param>
        /// <param name="FontSize">Table's default font size.</param>
        public PdfTable(
			PdfPage		Page,
			PdfContents	Contents,
			PdfFont		Font = null,
			Double		FontSize = 9.0
			)
        {
            // save arguments
            this.Document = Page.Document;
            this.Page = Page;
            this.Contents = Contents;

            // See if at least one font is defined. Make it the default font for the table
            if(Font == null) foreach(PdfObject Obj in Document.ObjectArray) if(Obj.GetType() == typeof(PdfFont))
            {
            Font = (PdfFont) Obj;
            break;
            }

            // initialize default cell style
            DefaultCellStyle = new PdfTableStyle();
            DefaultCellStyle.Font = Font;
            DefaultCellStyle.FontSize = FontSize;
            DefaultCellStyle.Margin.Left = DefaultCellStyle.Margin.Right = 3.0 / Document.ScaleFactor;
            DefaultCellStyle.Margin.Bottom = DefaultCellStyle.Margin.Top = 1.0 / Document.ScaleFactor;

            // initialize default header style
            DefaultHeaderStyle = CellStyle;
            DefaultHeaderStyle.BackgroundColor = Color.LightGray;

            // default table area
            TableArea = new PdfRectangle(72.0 / Document.ScaleFactor, 72.0 / Document.ScaleFactor,
            (Document.PageSize.Width - 72.0) / Document.ScaleFactor, (Document.PageSize.Height - 72.0) / Document.ScaleFactor);

            // set header on each page as the default
            HeaderOnEachPage = true;

            // create table border control
            Borders = new PdfTableBorder(this);

            // very small amount 1/300 of an inch
            // used to guard against rounding errors
            Epsilon = 1.0 / (300.0 * Document.ScaleFactor);
            return;
        }
Пример #6
0
        /// <summary>
        /// PdfAnnotation constructor
        /// </summary>
        /// <param name="AnnotPage">Page object</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="AnnotAction">Annotation action</param>
        internal PdfAnnotation
        (
            PdfPage AnnotPage,
            PdfRectangle AnnotRect,
            AnnotAction AnnotAction
        ) : base(AnnotPage.Document)
        {
            // save arguments
            this.AnnotPage   = AnnotPage;
            this.AnnotRect   = AnnotRect;
            this.AnnotAction = AnnotAction;

            // annotation subtype
            Dictionary.Add("/Subtype", AnnotAction.Subtype);

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // web link
            if (AnnotAction.GetType() == typeof(AnnotWebLink))
            {
                Dictionary.AddIndirectReference("/A", PdfWebLink.AddWebLink(Document, ((AnnotWebLink)AnnotAction).WebLinkStr));
            }

            // jump to destination
            else if (AnnotAction.GetType() == typeof(AnnotLinkAction))
            {
                if (Document.LinkAnnotArray == null)
                {
                    Document.LinkAnnotArray = new List <PdfAnnotation>();
                }
                Document.LinkAnnotArray.Add(this);
            }

            // display video or play sound
            else if (AnnotAction.GetType() == typeof(AnnotDisplayMedia))
            {
                PdfDisplayMedia DisplayMedia = ((AnnotDisplayMedia)AnnotAction).DisplayMedia;

                // action reference dictionary
                Dictionary.AddIndirectReference("/A", DisplayMedia);

                // add page reference
                Dictionary.AddIndirectReference("/P", AnnotPage);

                // add annotation reference
                DisplayMedia.Dictionary.AddIndirectReference("/AN", this);
            }

            // file attachment
            else if (AnnotAction.GetType() == typeof(AnnotFileAttachment))
            {
                // add file attachment reference
                AnnotFileAttachment File = (AnnotFileAttachment)AnnotAction;
                Dictionary.AddIndirectReference("/FS", File.EmbeddedFile);

                if (File.Icon != FileAttachIcon.NoIcon)
                {
                    // icon
                    Dictionary.AddName("/Name", File.Icon.ToString());
                }
                else
                {
                    // no icon
                    PdfXObject XObject = new PdfXObject(Document, AnnotRect.Right, AnnotRect.Top);
                    Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", XObject.ObjectNumber);
                }
            }

            // sticky notes
            else if (AnnotAction.GetType() == typeof(AnnotStickyNote))
            {
                // short cut
                AnnotStickyNote StickyNote = (AnnotStickyNote)AnnotAction;

                // icon
                Dictionary.AddName("/Name", StickyNote.Icon.ToString());

                // action reference dictionary
                Dictionary.AddPdfString("/Contents", StickyNote.Note);
            }

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = AnnotPage.Dictionary.GetValue("/Annots");

            if (KeyValue == null)
            {
                AnnotPage.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
                AnnotPage.Dictionary.Add("/Annots", ((string)KeyValue.Value).Replace("]", string.Format(" {0} 0 R]", ObjectNumber)));
            }

            // exit
            return;
        }
        ////////////////////////////////////////////////////////////////////
        // Add key value pair to dictionary.
        // The value is string format
        ////////////////////////////////////////////////////////////////////
        internal void AddRectangle(
			String			Key,		// key (first character must be forward slash /)
			PdfRectangle	Rect
			)
        {
            AddRectangle(Key, Rect.Left, Rect.Bottom, Rect.Right, Rect.Top);
            return;
        }
        /// <summary>
        /// PDF link annotation constructor
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="WebLink">Weblink</param>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfWebLink			WebLink
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/Link");

            // action reference dictionary
            Dictionary.AddIndirectReference("/A", WebLink);

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
        private void ContructorHelper(
			PdfPage				Page,
			PdfRectangle		AnnotRect
			)
        {
            // save rectangle
            this.AnnotRect = AnnotRect;

            // area rectangle on the page
            Dictionary.AddRectangle("/Rect", AnnotRect);

            // annotation flags. value of 4 = Bit position 3 print
            Dictionary.Add("/F", "4");

            // add annotation object to page dictionary
            PdfKeyValue KeyValue = Page.Dictionary.GetValue("/Annots");
            if(KeyValue == null)
            {
            Page.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber);
            }

            else
            {
            Page.Dictionary.Add("/Annots", ((String) KeyValue.Value).Replace("]", String.Format(" {0} 0 R]", ObjectNumber)));
            }

            // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border
            Dictionary.Add("/BS", "<</W 0>>");

            // exit
            return;
        }
Пример #10
0
        /// <summary>
        /// File attachement
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="EmbeddedFile">Embedded file name</param>
        /// <param name="Icon">Icon</param>
        /// <remarks>
        /// <para>
        /// PDF specifications File Attachment Annotation page 637 table 8.35
        /// </para>
        /// </remarks>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfEmbeddedFile		EmbeddedFile,
			FileAttachIcon		Icon = FileAttachIcon.PushPin
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/FileAttachment");

            // add page reference
            Dictionary.AddIndirectReference("/FS", EmbeddedFile);

            // icon
            Dictionary.AddName("/Name", Icon.ToString());

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
Пример #11
0
        /// <summary>
        /// PDF screen annotation constructor
        /// </summary>
        /// <param name="Page">Associated page</param>
        /// <param name="AnnotRect">Annotation rectangle</param>
        /// <param name="DisplayMedia">Display media class</param>
        public PdfAnnotation(
			PdfPage				Page,
			PdfRectangle		AnnotRect,
			PdfDisplayMedia		DisplayMedia
			)
            : base(Page.Document)
        {
            // annotation subtype
            Dictionary.Add("/Subtype", "/Screen");

            // action reference dictionary
            Dictionary.AddIndirectReference("/A", DisplayMedia);
            this.DisplayMedia = DisplayMedia;

            // add page reference
            Dictionary.AddIndirectReference("/P", Page);

            // add annotation reference
            DisplayMedia.Dictionary.AddIndirectReference("/AN", this);

            // constructor helper method
            ContructorHelper(Page, AnnotRect);

            // exit
            return;
        }
Пример #12
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add weblink to this page
        /// </summary>
        /// <param name="WeblinkArea">Weblink area</param>
        /// <param name="WebLinkStr">Hyperlink string</param>
        /// <remarks>
        /// <para>
        ///	The four position arguments are in relation to the
        ///	bottom left corner of the paper.
        ///	If web link is empty, ignore this call.
        /// </para>
        /// <para>
        /// For more information go to <a href="http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version#WeblinkSupport">2.7 Web Link Support</a>
        /// </para>
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void AddWebLink(
            PdfRectangle	WeblinkArea,
            String			WebLinkStr
            )
        {
            // if web link is empty, ignore this call
            if(String.IsNullOrWhiteSpace(WebLinkStr)) return;

            // create weblink action or reuse duplicate
            PdfWebLink WebLinkAction = PdfWebLink.AddWebLink(Document, WebLinkStr);

            // create PdfObject for annotation
            PdfAnnotation Annotation = new PdfAnnotation(this, WeblinkArea, WebLinkAction);

            // exit
            return;
        }
Пример #13
0
        /// <summary>
        /// Add rendering screen action to page
        /// </summary>
        /// <param name="Rect">Annotation rectangle</param>
        /// <param name="FileName">Media file name</param>
        /// <param name="WidthPix">Video width in pixels</param>
        /// <param name="HeightPix">Video height in pixels</param>
        /// <param name="MimeType">Media file Mime type</param>
        public void AddScreenAction(
            PdfRectangle	Rect,
            String			FileName,
            Int32			WidthPix = 0,
            Int32			HeightPix = 0,
            String			MimeType = null
            )
        {
            // create embedded media file
            PdfEmbeddedFile MediaFile = new PdfEmbeddedFile(Document, FileName);

            // Section 8.5 page 669 table 8.64
            PdfDisplayMedia ScreenAction = new PdfDisplayMedia(MediaFile, MimeType);

            // create PdfObject for annotation
            PdfAnnotation Annotation = new PdfAnnotation(this, Rect, ScreenAction);

            //		Annotation.DisplayBorder(0.1);

            // exit
            return;
        }
Пример #14
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Copy one style to another 
        /// </summary>
        /// <param name="SourceStyle">Source style</param>
        ////////////////////////////////////////////////////////////////////
        public void Copy(
			PdfTableStyle	SourceStyle
			)
        {
            Alignment = SourceStyle.Alignment;
            BackgroundColor = SourceStyle.BackgroundColor;
            BarcodeBarWidth = SourceStyle.BarcodeBarWidth;
            BarcodeHeight = SourceStyle.BarcodeHeight;
            TextBoxFirstLineIndent = SourceStyle.TextBoxFirstLineIndent;
            TextBoxLineBreakFactor = SourceStyle.TextBoxLineBreakFactor;
            TextBoxLineExtraSpace = SourceStyle.TextBoxLineExtraSpace;
            TextBoxParagraphExtraSpace = SourceStyle.TextBoxParagraphExtraSpace;
            TextBoxTextJustify = SourceStyle.TextBoxTextJustify;
            Font = SourceStyle.Font;
            FontSize = SourceStyle.FontSize;
            ForegroundColor = SourceStyle.ForegroundColor;
            Format = SourceStyle.Format;
            Margin = new PdfRectangle(SourceStyle.Margin);
            RaiseCustomDrawCellEvent = SourceStyle.RaiseCustomDrawCellEvent;
            TextDrawStyle = SourceStyle.TextDrawStyle;
            MinHeight = SourceStyle.MinHeight;
            MultiLineText = SourceStyle.MultiLineText;
            NumberFormatInfo = SourceStyle.NumberFormatInfo;
            return;
        }