How to fill rectangle with some color

Hi,


While working with Rectangle, I need to fill the rectangle with some color. I tried using rectangle.GraphInfo.FillColor = Aspose.Pdf.Color.Red;

But rectangle is not filled with color red. Please let me know if i am missing something.

Regards,
Sandeep

Hi Sandeep,

Please try using the following code snippet to accomplish your requirement.

For your reference, I have also attached the resultant PDF generated on our team’s end.

[C#]

Pdf pdf = new Pdf();
pdf.Sections.Add();

//Create a graph object in the section with Width=100 and Height=400
Aspose.Pdf.Generator.Graph graph1 = new Aspose.Pdf.Generator.Graph(pdf.Sections[0], 100, 400);
Aspose.Pdf.Generator.Rectangle rectangle = new Aspose.Pdf.Generator.Rectangle(graph1, 100, 100, 200, 120);
rectangle.GraphInfo.FillColor = new Aspose.Pdf.Generator.Color("Red");

//Enable the circle to be filled with the color specified above line
rectangle.GraphInfo.IsFilled = true;

//Add the graph object to the paragraphs collection of the section
graph1.Shapes.Add(rectangle);
pdf.Sections[0].Paragraphs.Add(graph1);
pdf.Save("c:/pdftest/FilledRectangle.pdf");

Thanks for your reply. But Aspose has suggested to Move from Aspose.Pdf.Generator to Aspose.Pdf namespace. And now we are using Document class not Pdf. It will be helpful if you give example for Document object.


Regards,
Sandeep

Hi Sandeep,

Thanks for sharing the feedback.

I am afraid currently Aspose.Pdf.Rectangle does not support the feature to fill with some color. However for the sake of implementation, I have logged this requirement in our issue tracking system as PDFNEWNET-37502. We will investigate this issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWNET-37502) have been fixed in Aspose.Pdf for .NET 9.8.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

I tried to fill color in rectangle. I am using version 11.8.


I am using following code.

Document doc = new Document();
Page page = doc.Pages.Add();
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
page.Paragraphs.Add(canvas);
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(10, 100, 200, 100);
rect.GraphInfo.Color = Aspose.Pdf.Color.Red;
rect.GraphInfo.DashArray = new int[] { 1};
rect.GraphInfo.FillColor = Aspose.Pdf.Color.Blue;
rect.GraphInfo.DashPhase = 5;
rect.RoundedCornerRadius = 10;
canvas.Shapes.Add(rect);
canvas.Shapes.Add(rect);
doc.Save(“test.pdf”);


It is not filling the rectangle. Please let me know if i have missed something.

Regards,
Sandeep

Hi Sandeep,


Thanks for your inquriy. I have tested the scenario and noticed that API is not filling rounded corner as expected, so we have logged a ticket PDFNET-41204 in our issue tracking system for further assistance. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,