This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

pdf & color change

I have a pdf file that has many curves, the curves have different fill colors.

Can it be edited? changing fill colors, line colors, etc.,

My next question will be whether it is possible to fill such an object with a raster texture...




var dpi = 300f;

            using (var pdfWriter = new PdfWriter("out.pdf"))
            {
                pdfWriter.AddPage(
                        UnitConverter.ConvertUnitsToPixels(dpi, 21.0f, Unit.Cm),
                        UnitConverter.ConvertUnitsToPixels(dpi, 29.7f, Unit.Cm),
                        dpi, dpi);

                using (var graphics = pdfWriter.GetGraphics())
                {
                    using (var pdfReader = new PdfReader("in.pdf", dpi, dpi))
                    using (var pdfContent = pdfReader.Frames[0].GetContent())
                    {

                      // pdfContent.Items[5] < here would like to edit this item

                        graphics.DrawContainer(pdfContent,
                                UnitConverter.ConvertUnitsToPixels(dpi, 5.0f, Unit.Cm),
                                UnitConverter.ConvertUnitsToPixels(dpi, 5.0f, Unit.Cm)
                            );
                    }
                }
            }


I will be very grateful for advice on how to achieve this
Hi,

Please check this sample:
static void ConvertItems(GraphicsContainer gc)
{
    foreach (ShapeItem item in gc.Items.OfType<ShapeItem>())
    {
        if (item.Brush != null)
        {                    
            using (var bitmap = new Bitmap(rasterPath))                    
            {
                var brush = new TilingBrush(bitmap.Width, bitmap.Height, bitmap.DpiX, bitmap.DpiY);
                brush.Graphics.DrawImage(bitmap, 0, 0);
                item.Brush = brush;
            }
        }
    }

    foreach (ImageItem item in gc.Items.OfType<ImageItem>())
    {
        item.Bitmap.Transforms.Invert();
    }

    foreach (ContainerItem item in gc.Items.OfType<ContainerItem>())
    {
        ConvertItems(item.GraphicsContainer);
    }
}
static void ConvertPDF()
{
    using (var reader = new PdfReader(srcPath))
    using (var content = reader.Frames[0].GetContent())
    {
        ConvertItems(content);

        using (var writer = new PdfWriter(dstPath))
        using (var gr = writer.GetGraphics())
        {
            writer.AddPage(content.Width, content.Height, content.DpiX, content.DpiY);

            gr.DrawContainer(content, 0, 0);
        }
    }
}