Example #1
0
        /// <summary>
        /// Enumerates the elements of graphics container
        /// </summary>
        private static void EnumContentItems(string inPdf)
        {
            using (var reader = new PdfReader(inPdf))
                using (var gc = reader.Frames[0].GetContent())
                    using (var callbackContainer = new GraphicsContainer(gc.Width, gc.Height, gc.DpiX, gc.DpiY))
                        using (var gr = callbackContainer.GetGraphics())
                        {
                            gr.BeforeDrawPath += (sender, e) =>
                            {
                                if (e.Pen != null)
                                {
                                    Console.WriteLine(string.Format("Stroke: {0}", e.Pen.Color.ToString()));
                                }

                                if (e.Brush != null)
                                {
                                    Console.WriteLine(string.Format("Fill: {0}", e.Brush.ToString()));
                                }

                                e.Cancel = true;
                            };

                            gr.BeforeDrawImage += (sender, e) =>
                            {
                                Console.WriteLine(string.Format("Bitmap: {0} x {1}", e.Bitmap.Width, e.Bitmap.Height));

                                e.Cancel = true;
                            };

                            gr.DrawContainer(gc, 0, 0);
                        }
        }
Example #2
0
        /// <summary>
             /// Updates text and shape color of PSD image and saves to PDF file
             /// </summary>
        private static void UpdateTextAndShapeColor()
        {
            var psdProcessor = new PsdProcessor();

            psdProcessor.TextCallback = (processor, textFrame, textString) =>
            {
                var text = processor.ProcessText(textFrame);
                text.String = textString;

                text.Brush = new SolidBrush(RgbColor.DarkRed);

                return(text);
            };

            psdProcessor.FrameCallback = (processor, frame) =>
            {
                if (frame.Type != FrameType.Shape)
                {
                    return(processor.ProcessFrame(frame));
                }

                var shapeFrame = (PsdShapeFrame)frame;

                var graphicsContainer = new GraphicsContainer(frame.X + frame.Width, frame.Y + frame.Height, frame.DpiX, frame.DpiY);

                using (var graphics = graphicsContainer.GetGraphics())
                {
                    graphics.FillPath(new SolidBrush(RgbColor.DarkGreen), shapeFrame.VectorMask);
                }

                return(graphicsContainer);
            };

            psdProcessor.Render(@"../../../../_Input/idtestback.psd", @"../../../../_Output/UpdateTextAndShapeColor.pdf");
        }
Example #3
0
    /// <summary>
    /// Creates a vignette with a specified color
    /// </summary>
    private static void CreateVignette(string srcPath, Color color, string dstPath)
    {
        const float borderScale     = 0.05f;
        const float blurRadiusScale = borderScale / 2.0f;

        using (var reader = ImageReader.Create(srcPath))
            using (var gc = new GraphicsContainer(reader.Width, reader.Height, reader.DpiX, reader.DpiY))
                using (var gr = gc.GetGraphics())
                {
                    int offset = (int)(reader.Width * borderScale);

                    gr.FillEllipse(new SolidBrush(RgbColor.White), offset, offset, gc.Width - 2 * offset, gc.Height - 2 * offset);

                    // One pipeline for generating an alpha channel

                    var alphaPipeline = new Pipeline();
                    alphaPipeline.Add(new ImageGenerator(gc, PixelFormat.Format8bppGrayscale, RgbColor.Black));
                    alphaPipeline.Add(new Blur(reader.Width * blurRadiusScale));

                    // And another one for getting a final content

                    var pipeline = new Pipeline();
                    pipeline.Add(reader);
                    pipeline.Add(new ScaleAlpha(alphaPipeline));
                    pipeline.Add(new RemoveAlpha(color));
                    pipeline.Add(ImageWriter.Create(dstPath));

                    try
                    {
                        pipeline.Run();
                    }
                    finally
                    {
                        pipeline.DisposeAllElements();
                        alphaPipeline.DisposeAllElements();
                    }
                }
    }