Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
MateuszŁ  
#1 Posted : Tuesday, June 6, 2023 2:37:06 AM(UTC)
MateuszŁ

Rank: Newbie

Groups: Member
Joined: 2/7/2019(UTC)
Posts: 9

Thanks: 6 times
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...

Code:

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

Eugene Kosmin  
#2 Posted : Tuesday, June 6, 2023 8:34:44 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hi,

Please check this sample:

Code:
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);
        }
    }
}
Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
MateuszŁ on 6/6/2023(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.