static void Main(string[] args)
        {
            using (Library lib = new Library())
            {
                String sOutput = "../Indexed-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font    = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);

                ColorSpace baseCS = ColorSpace.DeviceRGB;

                List <Int32> lookup = new List <Int32>();

                int[] lowhi = { 0, 255 };
                foreach (int r in lowhi)
                {
                    foreach (int g in lowhi)
                    {
                        foreach (int b in lowhi)
                        {
                            lookup.Add(r);
                            lookup.Add(g);
                            lookup.Add(b);
                        }
                    }
                }

                IndexedColorSpace cs = new IndexedColorSpace(baseCS, 7, lookup);

                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new Double[] { 4.0 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
        static void Main(string[] args)
        {
            // ReSharper disable once UnusedVariable
            using (Library lib = new Library())
            {
                String sOutput = "Indexed-out.pdf";

                if (args.Length > 0)
                {
                    sOutput = args[0];
                }

                Console.WriteLine("Writing to output " + sOutput);

                Document doc     = new Document();
                Page     page    = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72));
                Content  content = page.Content;
                Font     font;
                try
                {
                    font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset);
                }
                catch (ApplicationException ex)
                {
                    if (ex.Message.Equals("The specified font could not be found.") &&
                        System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
                                                                                       .OSPlatform.Linux) &&
                        !System.IO.Directory.Exists("/usr/share/fonts/msttcore/"))
                    {
                        Console.WriteLine("Please install Microsoft Core Fonts on Linux first.");
                        return;
                    }

                    throw;
                }

                ColorSpace baseCS = ColorSpace.DeviceRGB;

                List <Int32> lookup = new List <Int32>();

                int[] lowhi = { 0, 255 };
                foreach (int r in lowhi)
                {
                    foreach (int g in lowhi)
                    {
                        foreach (int b in lowhi)
                        {
                            lookup.Add(r);
                            lookup.Add(g);
                            lookup.Add(b);
                        }
                    }
                }

                IndexedColorSpace cs = new IndexedColorSpace(baseCS, 7, lookup);

                GraphicState gs = new GraphicState();
                gs.FillColor = new Color(cs, new[] { 4.0 });


                Matrix textMatrix = new Matrix(24, 0, 0, 24,    // Set font width and height to 24 point size
                                               1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2"

                TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix);
                Text    text    = new Text();
                text.AddRun(textRun);
                content.AddElement(text);
                page.UpdateContent();

                doc.EmbedFonts();
                doc.Save(SaveFlags.Full, sOutput);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get one color space
        /// </summary>
        public static IColorSpace CreateColorSpace(string colorSpaceName, PdfArray colorSpaceArray)
        {
            IColorSpace colorSpace = null;

            switch (colorSpaceName)
            {
            case PdfKeys.DefaultRGB:
            case PdfKeys.DeviceRGB:
            {
                colorSpace = new RGBDeviceColorSpace();
                break;
            }

            case PdfKeys.DefaultCMYK:
            case PdfKeys.DeviceCMYK:
            {
                colorSpace = new CMYKDeviceColorSpace();
                break;
            }

            case PdfKeys.DefaultGray:
            case PdfKeys.DeviceGray:
            {
                colorSpace = new GrayDeviceColorSpace();
                break;
            }

            case PdfKeys.ICCBased:
            {
                colorSpace = new ICCBasedColorSpace();
                break;
            }

            case PdfKeys.Indexed:
            {
                colorSpace = new IndexedColorSpace();
                break;
            }

            case PdfKeys.DeviceN:
            {
                colorSpace = new DeviceNColorSpace();
                break;
            }

            case PdfKeys.CalGray:
            {
                colorSpace = new UnknownColorSpace(1);
                break;
            }

            case PdfKeys.CalRGB:
            {
                colorSpace = new UnknownColorSpace(3);
                break;
            }

            case PdfKeys.Lab:
            {
                colorSpace = new UnknownColorSpace(3);
                break;
            }

            default:
            {
                colorSpace = new UnknownColorSpace(1);
                break;
            }
            }

            colorSpace.Init(colorSpaceArray);

            return(colorSpace);
        }