Rank: Newbie
Groups: Guest
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
|
|
|
|
Rank: Advanced Member
Groups: Guest
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
|
1 user thanked Eugene Kosmin for this useful post.
|
|
|
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.