Esempio n. 1
0
            public void ShouldReturnFalseWhenOtherAsObjectIsNotEqual()
            {
                var color = new ColorGray(1);
                var other = new ColorGray(0.5);

                Assert.False(color.Equals((object)other));
            }
Esempio n. 2
0
            public void ShouldReturnTrueWhenOtherAsObjectIsEqual()
            {
                var color = new ColorGray(1);
                var other = new ColorGray(1);

                Assert.True(color.Equals((object)other));
            }
Esempio n. 3
0
        /// <summary>
        /// Allows the creation of a shallow copy of this Bytescout.PDF.ColorGray.
        /// </summary>
        /// <returns cref="object" href="http://msdn.microsoft.com/en-us/library/system.object.aspx">Returns a shallow copy of this Bytescout.PDF.ColorGray.</returns>
        public override object Clone()
        {
            ColorGray p = this.MemberwiseClone() as ColorGray;

            p._colorspace = _colorspace.Clone() as Colorspace;
            return(p);
        }
Esempio n. 4
0
            public void ShouldReturnTheCorrectValueWhenOtherIsHigher()
            {
                var color = new ColorGray(0.25);
                var other = new ColorGray(0.5);

                Assert.Equal(-1, color.CompareTo(other));
            }
Esempio n. 5
0
        /// <summary>
        /// Get the WPF color from a gray color definition
        /// </summary>
        private (Color, GraphicColorPrecision) GetColor(ColorGray grayColor)
        {
            int   gray  = (int)(grayColor.Gray / 100.0 * 255.0 + 0.5);
            Color color = Color.FromRgb((byte)gray, (byte)gray, (byte)gray);

            return(color, GraphicColorPrecision.Precise);
        }
            public void ShouldInitializeTheProperties()
            {
                var color     = new MagickColor(Quantum.Max, (QuantumType)(Quantum.Max * 0.25), (QuantumType)(Quantum.Max * 0.5));
                var grayColor = ColorGray.FromMagickColor(color);

                Assert.InRange(grayColor.Shade, 0.41, 0.43);
            }
Esempio n. 7
0
            public void ShouldReturnDifferentValueWhenChannelChanged()
            {
                var first    = new ColorGray(0.0);
                var hashCode = first.GetHashCode();

                first.Shade = 1.0;
                Assert.NotEqual(hashCode, first.GetHashCode());
            }
Esempio n. 8
0
        /// <summary>
        /// Determines whether the specified Bytescout.PDF.ColorGray is equal to the current Bytescout.PDF.ColorGray.
        /// </summary>
        /// <param name="obj" href="http://msdn.microsoft.com/en-us/library/system.object.aspx">The System.Object to compare with the current Bytescout.PDF.ColorGray.</param>
        /// <returns cref="bool" href="http://msdn.microsoft.com/en-us/library/system.boolean.aspx">true if the specified System.Object is equal to the current Bytescout.PDF.ColorGray; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            if (!(obj is ColorGray))
            {
                return(false);
            }
            ColorGray color = obj as ColorGray;

            return(color._g == _g);
        }
Esempio n. 9
0
            public void ShouldReturnTheCorrectValueWhenInstancesAreNotEqual()
            {
                var first  = new ColorGray(0.5);
                var second = new ColorGray(0);

                Assert.False(first == second);
                Assert.True(first != second);
                Assert.False(first < second);
                Assert.False(first <= second);
                Assert.True(first > second);
                Assert.True(first >= second);
            }
Esempio n. 10
0
            public void ShouldSetTheCorrectValue()
            {
                var color = new ColorGray(0);

                color.Shade = 1;
                Assert.Equal(1, color.Shade);

                color.Shade = -0.99;
                Assert.Equal(1, color.Shade);

                color.Shade = 1.01;
                Assert.Equal(1, color.Shade);
            }
Esempio n. 11
0
            public void ShouldReturnTheCorrectValueWhenInstanceIsNull()
            {
                var color = new ColorGray(0);

                Assert.False(color is null);
                Assert.True(color != null);
                Assert.False(color < null);
                Assert.False(color <= null);
                Assert.True(color > null);
                Assert.True(color >= null);
                Assert.False(null == color);
                Assert.True(null != color);
                Assert.True(null < color);
                Assert.True(null <= color);
                Assert.False(null > color);
                Assert.False(null >= color);
            }
Esempio n. 12
0
            public void ShouldReturnTheCorrectValueWhenOtherIsEqual()
            {
                var color = new ColorGray(1);

                Assert.Equal(0, color.CompareTo(color));
            }
Esempio n. 13
0
        private void Convert_Button_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "RGB_Button":
                try
                {
                    if (RGBSpace != RGBSpaceName.ICC)
                    {
                        ColRGB = new ColorRGB(RGBSpace, RGB[0], RGB[1], RGB[2]);
                    }
                    else
                    {
                        ColRGB = new ColorRGB(RGB_ICC, RGB[0], RGB[1], RGB[2]);
                    }
                    Conversion(ColRGB);
                }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "XYZ_Button":
                try { ColXYZ = new ColorXYZ(XYZwp, XYZ[0], XYZ[1], XYZ[2]); Conversion(ColXYZ); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "Lab_Button":
                try { ColLab = new ColorLab(Labwp, Lab[0], Lab[1], Lab[2]); Conversion(ColLab); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "Luv_Button":
                try { ColLuv = new ColorLuv(Luvwp, Luv[0], Luv[1], Luv[2]); Conversion(ColLuv); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "Yxy_Button":
                try { ColYxy = new ColorYxy(Yxywp, Yxy[0], Yxy[1], Yxy[2]); Conversion(ColYxy); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCHab_Button":
                try { ColLCHab = new ColorLCHab(LCHabwp, LCHab[0], LCHab[1], LCHab[2]); Conversion(ColLCHab); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCHuv_Button":
                try { ColLCHuv = new ColorLCHuv(LCHuvwp, LCHuv[0], LCHuv[1], LCHuv[2]); Conversion(ColLCHuv); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCH99_Button":
                try { ColLCH99 = new ColorLCH99(LCH99[0], LCH99[1], LCH99[2]); Conversion(ColLCH99); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCH99b_Button":
                try { ColLCH99b = new ColorLCH99b(LCH99b[0], LCH99b[1], LCH99b[2]); Conversion(ColLCH99b); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCH99c_Button":
                try { ColLCH99c = new ColorLCH99c(LCH99c[0], LCH99c[1], LCH99c[2]); Conversion(ColLCH99c); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "LCH99d_Button":
                try { ColLCH99d = new ColorLCH99d(LCH99d[0], LCH99d[1], LCH99d[2]); Conversion(ColLCH99d); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "HSV_Button":
                try
                {
                    if (HSVSpace != RGBSpaceName.ICC)
                    {
                        ColHSV = new ColorHSV(HSVSpace, HSV[0], HSV[1], HSV[2]);
                    }
                    else
                    {
                        ColHSV = new ColorHSV(HSV_ICC, HSV[0], HSV[1], HSV[2]);
                    }
                    Conversion(ColHSV);
                }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "HSL_Button":
                try
                {
                    if (HSLSpace != RGBSpaceName.ICC)
                    {
                        ColHSL = new ColorHSL(HSLSpace, HSL[0], HSL[1], HSL[2]);
                    }
                    else
                    {
                        ColHSL = new ColorHSL(HSL_ICC, HSL[0], HSL[1], HSL[2]);
                    }
                    Conversion(ColHSL);
                }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "CMY_Button":
                try { ColCMY = new ColorCMY(CMY_ICC, CMY[0], CMY[1], CMY[2]); Conversion(ColCMY); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "CMYK_Button":
                try { ColCMYK = new ColorCMYK(CMYK_ICC, CMYK[0], CMYK[1], CMYK[2], CMYK[3]); Conversion(ColCMYK); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "Gray_Button":
                try
                {
                    if (Gray_ICC != null)
                    {
                        ColGray = new ColorGray(Gray_ICC, Gray[0]);
                    }
                    else
                    {
                        ColGray = new ColorGray(Gray[0]);
                    }
                    Conversion(ColGray);
                }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "YCbCr_Button":
                try
                {
                    if (YCbCrSpace == YCbCrSpaceName.ICC)
                    {
                        ColYCbCr = new ColorYCbCr(YCbCr_ICC, YCbCr[0], YCbCr[1], YCbCr[2]);
                    }
                    else
                    {
                        ColYCbCr = new ColorYCbCr(YCbCrSpace, YCbCr[0], YCbCr[1], YCbCr[2]);
                    }
                    Conversion(ColYCbCr);
                }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "XColor_Button":
                try { ColX = new ColorX(XColor_ICC, XColor.Take(XColor_Channels).ToArray()); Conversion(ColX); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "DEF_Button":
                try { ColDEF = new ColorDEF(DEFwp, DEF[0], DEF[1], DEF[2]); Conversion(ColDEF); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "Bef_Button":
                try { ColBef = new ColorBef(Befwp, Bef[0], Bef[1], Bef[2]); Conversion(ColBef); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;

            case "BCH_Button":
                try { ColBCH = new ColorBCH(BCHwp, BCH[0], BCH[1], BCH[2]); Conversion(ColBCH); }
                catch (FormatException) { MessageBox.Show("Not a number!"); }
                catch (Exception ex) { MessageBox.Show("Error:" + Environment.NewLine + ex.Message); }
                break;
            }
        }
Esempio n. 14
0
        private void Conversion(Color inColor)
        {
            Color inColor2 = inColor;

            if (inColor.IsICCcolor && !inColor.IsPCScolor)
            {
                inColor2 = Converter.ToICC(inColor);
            }

            if (inColor.Model != ColorModel.CIEXYZ)
            {
                ColXYZ = Converter.ToXYZ(inColor2, XYZwp);
            }
            if (inColor.Model != ColorModel.CIELab)
            {
                ColLab = Converter.ToLab(inColor2, Labwp);
            }
            if (inColor.Model != ColorModel.CIELuv)
            {
                ColLuv = Converter.ToLuv(inColor2, Luvwp);
            }
            if (inColor.Model != ColorModel.CIELCHab)
            {
                ColLCHab = Converter.ToLCHab(inColor2, LCHabwp);
            }
            if (inColor.Model != ColorModel.CIELCHuv)
            {
                ColLCHuv = Converter.ToLCHuv(inColor2, LCHuvwp);
            }
            if (inColor.Model != ColorModel.CIEYxy)
            {
                ColYxy = Converter.ToYxy(inColor2, Yxywp);
            }
            if (inColor.Model != ColorModel.LCH99)
            {
                ColLCH99 = Converter.ToLCH99(inColor2);
            }
            if (inColor.Model != ColorModel.LCH99b)
            {
                ColLCH99b = Converter.ToLCH99b(inColor2);
            }
            if (inColor.Model != ColorModel.LCH99c)
            {
                ColLCH99c = Converter.ToLCH99c(inColor2);
            }
            if (inColor.Model != ColorModel.LCH99d)
            {
                ColLCH99d = Converter.ToLCH99d(inColor2);
            }
            if (inColor.Model != ColorModel.DEF)
            {
                ColDEF = Converter.ToDEF(inColor2);
            }
            if (inColor.Model != ColorModel.Bef)
            {
                ColBef = Converter.ToBef(inColor2);
            }
            if (inColor.Model != ColorModel.BCH)
            {
                ColBCH = Converter.ToBCH(inColor2);
            }

            if (inColor.Model != ColorModel.RGB)
            {
                if (RGBSpace != RGBSpaceName.ICC)
                {
                    ColRGB = Converter.ToRGB(inColor2, RGBSpace);
                }
                else
                {
                    ColRGB = (ColorRGB)Converter.ToICC(Converter.ToICC_PCS(inColor2, RGB_ICC), RGB_ICC);
                }
            }
            if (inColor.Model != ColorModel.HSV)
            {
                if (HSVSpace != RGBSpaceName.ICC)
                {
                    ColHSV = Converter.ToHSV(inColor2, HSVSpace);
                }
                else
                {
                    ColHSV = (ColorHSV)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSV_ICC), HSV_ICC);
                }
            }
            if (inColor.Model != ColorModel.HSL)
            {
                if (HSLSpace != RGBSpaceName.ICC)
                {
                    ColHSL = Converter.ToHSL(inColor2, HSLSpace);
                }
                else
                {
                    ColHSL = (ColorHSL)Converter.ToICC(Converter.ToICC_PCS(inColor2, HSL_ICC), HSL_ICC);
                }
            }
            if (inColor.Model != ColorModel.CMY && CMY_ICC != null)
            {
                ColCMY = (ColorCMY)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMY_ICC), CMY_ICC);
            }
            if (inColor.Model != ColorModel.CMYK && CMYK_ICC != null)
            {
                ColCMYK = (ColorCMYK)Converter.ToICC(Converter.ToICC_PCS(inColor2, CMYK_ICC), CMYK_ICC);
            }
            if (inColor.Model != ColorModel.YCbCr)
            {
                if (YCbCrSpace != YCbCrSpaceName.ICC)
                {
                    ColYCbCr = Converter.ToYCbCr(inColor2, YCbCrSpace);
                }
                else
                {
                    ColYCbCr = (ColorYCbCr)Converter.ToICC(Converter.ToICC_PCS(inColor2, YCbCr_ICC), YCbCr_ICC);
                }
            }
            if (inColor.Model != ColorModel.Gray)
            {
                if (CMY_ICC != null)
                {
                    ColGray = (ColorGray)Converter.ToICC(Converter.ToICC_PCS(inColor2, Gray_ICC), Gray_ICC);
                }
                else
                {
                    ColGray = Converter.ToGray(inColor2);
                }
            }
            if (!IsXColor(inColor.Model) && XColor_ICC != null)
            {
                ColX = (ColorX)Converter.ToICC(Converter.ToICC_PCS(inColor2, XColor_ICC), XColor_ICC);
            }

            FillFields();
        }
Esempio n. 15
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);


            DeviceColor lightGrayColor = new ColorGray(200);
            DeviceColor whiteColor     = new ColorGray(255);
            DeviceColor lightBlueColor = new ColorRGB(200, 200, 250);
            DeviceColor lightRedColor  = new ColorRGB(255, 200, 200);

            // Create a table and set default background color
            Table table = new Table();

            table.BackgroundColor = lightGrayColor;

            // Add row headers column and set its color
            table.Columns.Add(new TableColumn("RowHeaders"));
            table.Columns[0].BackgroundColor = lightGrayColor;

            // Add columns A, B, C, ...
            for (int c = 0; c < 10; c++)
            {
                string columnName = Convert.ToChar('A' + c).ToString();
                table.Columns.Add(new TableColumn(columnName, columnName));
            }

            // Add rows
            for (int r = 0; r < 10; r++)
            {
                // Create new row and set its background color
                TableRow row = table.NewRow();
                row.BackgroundColor = whiteColor;

                // Set row header text
                row["RowHeaders"].Text = (r + 1).ToString();

                // Set cell text
                for (int c = 0; c < 10; c++)
                {
                    string columnName = Convert.ToChar('A' + c).ToString();
                    row[columnName].Text = columnName + (r + 1);
                }

                // Add the row to the table
                table.Rows.Add(row);
            }

            // Decorate the table
            table.Rows[1]["B"].BackgroundColor          = lightRedColor;
            table.Columns[2].BackgroundColor            = lightBlueColor;
            table.Rows[1].BackgroundColor               = lightBlueColor;
            table.Rows[1]["RowHeaders"].BackgroundColor = lightBlueColor;

            // Draw the table on canvas
            page.Canvas.DrawTable(table, 20, 20);


            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer app
            Process.Start("result.pdf");
        }
        /// <summary>
        /// Demonstrate PDF Table Creations
        /// </summary>
        /// <returns></returns>
        private FileResult _DemonstrateTableCreation()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // Add page
            Bytescout.PDF.Page page = new Bytescout.PDF.Page(PaperFormat.A4);
            pdfDocument.Pages.Add(page);

            DeviceColor lightGrayColor = new ColorGray(200);
            DeviceColor whiteColor     = new ColorGray(255);
            DeviceColor lightBlueColor = new ColorRGB(200, 200, 250);
            DeviceColor lightRedColor  = new ColorRGB(255, 200, 200);

            // Create a table and set default background color
            Bytescout.PDF.Table table = new Bytescout.PDF.Table();
            table.BackgroundColor = lightGrayColor;

            // Add row headers column and set its color
            table.Columns.Add(new TableColumn("RowHeaders"));
            table.Columns[0].BackgroundColor = lightGrayColor;

            // Add columns A, B, C, ...
            for (int c = 0; c < 10; c++)
            {
                string columnName = Convert.ToChar('A' + c).ToString();
                table.Columns.Add(new TableColumn(columnName, columnName));
            }

            // Add rows
            for (int r = 0; r < 10; r++)
            {
                // Create new row and set its background color
                Bytescout.PDF.TableRow row = table.NewRow();
                row.BackgroundColor = whiteColor;

                // Set row header text
                row["RowHeaders"].Text = (r + 1).ToString();

                // Set cell text
                for (int c = 0; c < 10; c++)
                {
                    string columnName = Convert.ToChar('A' + c).ToString();
                    row[columnName].Text = columnName + (r + 1);
                }

                // Add the row to the table
                table.Rows.Add(row);
            }

            // Decorate the table
            table.Rows[1]["B"].BackgroundColor          = lightRedColor;
            table.Columns[2].BackgroundColor            = lightBlueColor;
            table.Rows[1].BackgroundColor               = lightBlueColor;
            table.Rows[1]["RowHeaders"].BackgroundColor = lightBlueColor;

            // Draw the table on canvas
            page.Canvas.DrawTable(table, 20, 20);

            // Save created PDF to memory stream
            MemoryStream memoryStream = new MemoryStream();

            pdfDocument.Save(memoryStream);

            // Stream back to beginning to allow the data to be read back out
            memoryStream.Seek(0, SeekOrigin.Begin);

            // Return result
            return(File(memoryStream, "text/pdf", "sample_PDFWithTable.pdf"));
        }
Esempio n. 17
0
            public void ShouldReturnFalseWhenOtherAsObjectIsNull()
            {
                var color = new ColorGray(1);

                Assert.False(color.Equals((object)null));
            }
Esempio n. 18
0
        /// <summary>
        /// Handle Table Creation with PDF SDK
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnTableCreation_Click(object sender, EventArgs e)
        {
            try
            {
                // Create new document
                Document pdfDocument = new Document();
                pdfDocument.RegistrationName = "demo";
                pdfDocument.RegistrationKey  = "demo";

                // Add page
                Bytescout.PDF.Page page = new Bytescout.PDF.Page(PaperFormat.A4);
                pdfDocument.Pages.Add(page);

                DeviceColor lightGrayColor = new ColorGray(200);
                DeviceColor whiteColor     = new ColorGray(255);
                DeviceColor lightBlueColor = new ColorRGB(200, 200, 250);
                DeviceColor lightRedColor  = new ColorRGB(255, 200, 200);

                // Create a table and set default background color
                Bytescout.PDF.Table table = new Bytescout.PDF.Table();
                table.BackgroundColor = lightGrayColor;

                // Add row headers column and set its color
                table.Columns.Add(new TableColumn("RowHeaders"));
                table.Columns[0].BackgroundColor = lightGrayColor;

                // Add columns A, B, C, ...
                for (int c = 0; c < 10; c++)
                {
                    string columnName = Convert.ToChar('A' + c).ToString();
                    table.Columns.Add(new TableColumn(columnName, columnName));
                }

                // Add rows
                for (int r = 0; r < 10; r++)
                {
                    // Create new row and set its background color
                    Bytescout.PDF.TableRow row = table.NewRow();
                    row.BackgroundColor = whiteColor;

                    // Set row header text
                    row["RowHeaders"].Text = (r + 1).ToString();

                    // Set cell text
                    for (int c = 0; c < 10; c++)
                    {
                        string columnName = Convert.ToChar('A' + c).ToString();
                        row[columnName].Text = columnName + (r + 1);
                    }

                    // Add the row to the table
                    table.Rows.Add(row);
                }

                // Decorate the table
                table.Rows[1]["B"].BackgroundColor          = lightRedColor;
                table.Columns[2].BackgroundColor            = lightBlueColor;
                table.Rows[1].BackgroundColor               = lightBlueColor;
                table.Rows[1]["RowHeaders"].BackgroundColor = lightBlueColor;

                // Draw the table on canvas
                page.Canvas.DrawTable(table, 20, 20);

                // Save created PDF to memory stream
                MemoryStream memoryStream = new MemoryStream();
                pdfDocument.Save(memoryStream);

                // Perform download of file
                Response.Clear();
                Response.ClearHeaders();

                Response.AppendHeader("Content-Length", memoryStream.Length.ToString());
                Response.ContentType = "text/pdf";
                Response.AppendHeader("Content-Disposition", "attachment;filename=\"sample_PDFWithTable.pdf\"");

                Response.BinaryWrite(memoryStream.ToArray());
                Response.End();
            }
            catch (Exception ex)
            {
                lblTableCreation.Text = "Error: " + ex.Message;
            }
        }
            public void ShouldReturnNullWhenValueIsNull()
            {
                var result = ColorGray.FromMagickColor(null);

                Assert.Null(result);
            }
Esempio n. 20
0
        static void Main()
        {
            // Load XML document
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(@"sample.xml");

            // Read columns information from XML data
            List <string> columns        = new List <string>();
            XmlNodeList   columnNodeList = xmlDocument.SelectNodes("/Report/Columns/Column");

            foreach (XmlNode node in columnNodeList)
            {
                columns.Add(node.Attributes["Name"].Value);
            }

            // Read row nodes from XML data
            XmlNodeList rowNodeList = xmlDocument.SelectNodes("/Report/ReportData");


            // Create new PDF document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";
            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);

            DeviceColor lightGrayColor = new ColorGray(200);
            DeviceColor whiteColor     = new ColorGray(255);


            // Create PDF table
            Table table = new Table();

            table.BackgroundColor = lightGrayColor;

            // Add columns
            for (int c = 0; c < columns.Count; c++)
            {
                TableColumn column = new TableColumn(columns[c], columns[c]);
                // Set column width
                column.Width = (c == 0)? 100 : 60;
                table.Columns.Add(column);
            }

            // Add rows
            foreach (XmlNode rowNode in rowNodeList)
            {
                // Create new row and set its background color
                TableRow row = table.NewRow();
                row.BackgroundColor = whiteColor;

                // Get cell values from XML data
                foreach (XmlNode childNode in rowNode.ChildNodes)
                {
                    // Get cell info from XML data
                    string columnName  = childNode.Name;
                    int    columnIndex = columns.IndexOf(childNode.Name);
                    string cellValue   = childNode.InnerText;

                    // Set cell text
                    row[columnName].Text = cellValue;
                    // Set cell text alignment
                    row[columnName].TextFormat.HorizontalAlign = (columnIndex == 0) ? HorizontalAlign.Left : HorizontalAlign.Right;
                }

                // Add the row to the table
                table.Rows.Add(row);
            }

            // Draw the table on canvas
            page.Canvas.DrawTable(table, 20, 20);


            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open document in default PDF viewer application
            Process.Start("result.pdf");
        }
Esempio n. 21
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            // Add page
            Page page = new Page(PaperFormat.A4);

            pdfDocument.Pages.Add(page);


            DeviceColor lightGrayColor = new ColorGray(200);
            DeviceColor whiteColor     = new ColorGray(255);
            DeviceColor lightBlueColor = new ColorRGB(200, 200, 250);
            DeviceColor lightRedColor  = new ColorRGB(255, 200, 200);

            // Create a table and set default background color
            Table table = new Table();

            table.BackgroundColor = lightGrayColor;

            // Add row headers column and set its color
            table.Columns.Add(new TableColumn("RowHeaders"));
            table.Columns[0].BackgroundColor = lightGrayColor;

            // Add columns A, B, C, ...
            for (int c = 0; c < 10; c++)
            {
                string columnName = Convert.ToChar('A' + c).ToString();
                table.Columns.Add(new TableColumn(columnName, columnName));
            }

            // Add rows
            for (int r = 0; r < 10; r++)
            {
                // Create new row and set its background color
                TableRow row = table.NewRow();
                row.BackgroundColor = whiteColor;

                // Set row header text
                row["RowHeaders"].Text = (r + 1).ToString();

                // Set cell text
                for (int c = 0; c < 10; c++)
                {
                    string columnName = Convert.ToChar('A' + c).ToString();
                    row[columnName].Text = columnName + (r + 1);
                }

                // Add the row to the table
                table.Rows.Add(row);
            }

            // Decorate the table
            table.Rows[1]["B"].BackgroundColor          = lightRedColor;
            table.Columns[2].BackgroundColor            = lightBlueColor;
            table.Rows[1].BackgroundColor               = lightBlueColor;
            table.Rows[1]["RowHeaders"].BackgroundColor = lightBlueColor;

            // Draw the table on canvas
            page.Canvas.DrawTable(table, 20, 20);


            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }