Support for changing words color using Aspose.Slides .NET

I would like to change the balck words in a pptx file like:
“Black” to “¤Black¤” is there any way to do this?

@Nszolnoki,

I have observed your requirements and request you to please share them in the form of source presentation that what you want to achieve using Aspose.Slides. We will investigate that on our end to help you further.

@mudassir.fayyaz

Please find the input and wanted output file in the attachment zip.
I would like to flag the black text at its start and end with a “¤” sign.

output.zip (52.3 KB)

@Nszolnoki,

I have observed your comments. I have shared sample code with you. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.code.zip (709 Bytes)

Dear Adnan,

I tried to use the code you sent, unfortunately I get a lot of error about like:
image.png (45.6 KB)

Can you please help me with.
Thanks in advance!

@Nszolnoki,

I have observed your comments. Can you please try to use Aspose.Slides latest version 19.1 on your end and share feedback with us if there is still an issue. I have also shared screenshot with you for your kind reference.<2019-02-13 01_26_27-TestAsposeJava - NetBeans IDE 8.2.png (22.7 KB)

Hello,

I updated to the latest version, but I get the same issues.
We are talking about a C# code, is you snippet from JAVA, I am sorry if I did not mention that.
If it is, can you please help me to implement the same with C#.Screenshot_53.png (40.0 KB)

@Nszolnoki,

I have observed your comments. I have shared sample code in C#. Please check attachment and share feedback with us if there is still an issue..NETCODE.zip (677 Bytes)

Thank you, I tested with, but it did not added the “¤” signs, please check the source file is the:
test.pptx
the final file is:
text_replace.pptxtext_replace.zip (52.7 KB)

@Nszolnoki,

I suggest you to please try using following sample code on your end.

    public static void TestReplaceText()
    {
        String path = @"C:\Aspose Data\text_replace\";
        Presentation pres = new Presentation(path + "test.pptx");

        for (int i = 0; i < pres.Slides.Count; i++)
        {
            ISlide slide = pres.Slides[i];
            foreach (IShape shape in slide.Shapes)
            {
                IParagraphCollection paragraphCollection = ((IAutoShape)shape).TextFrame.Paragraphs;
                foreach (IParagraph para in paragraphCollection)
                {
                    IPortion first = null;
                    IPortion last = null;
                    IPortionCollection portions = para.Portions;
                    for (int p = 0; p < portions.Count; p++)
                    {
                        IPortion portion = portions[p];
                        IPortionFormat portFormat = portion.PortionFormat;
                       // IPortionFormatEffectiveData portFormat = portion.CreatePortionFormatEffective();
                        //if (portFormat.FillFormat.SolidFillColor.Color == Color.Black)
                            if (portFormat.FillFormat.SolidFillColor.Color.R==0 && portFormat.FillFormat.SolidFillColor.Color.G==0 
                                &&portFormat.FillFormat.SolidFillColor.Color.B==0)
                            {
                            if (first == null)
                            {
                                first = portion;
                            }

                            last = portion;
                        }

                        if (((portFormat.FillFormat.SolidFillColor.Color.R ==255
                   //     if (((portFormat.FillFormat.SolidFillColor == Color.Red
                                          || (p == portions.Count - 1)) && first != null && last != null))
                        {
                            if (first == last)
                            {
                                String portionText = first.Text;
                                first.Text = "¤" + portionText + "¤";
                            }
                            else
                            {
                                String firstPortionText = first.Text;
                                String lastPortionText = last.Text;
                                first.Text = "¤" + firstPortionText;
                                last.Text = lastPortionText + "¤";
                            }

                            first = null;
                            last = null;
                        }
                    }
                }
            }
        }

        pres.Save(path + "text_replace2.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
    }

Hello,

With the test file, it was worked amazingly, with a complicated file I got an invalid cast exception, as unfortnately I am not an expert of this API, I can’t figure it out.
Can you please check with the attached file.new_test.zip (3.8 MB)

@Nszolnoki,

The exception that you have received is owing accessing paragraph collection from a PictureFrame. Please use following amended sample code.

    public static void TestReplaceText()
    {
        String path = @"C:\Aspose Data\text_replace\";
        path = @"C:\Aspose Data\new_test\";
        Presentation pres = new Presentation(path + "new_test.pptx");

        for (int i = 0; i < pres.Slides.Count; i++)
        {
            ISlide slide = pres.Slides[i];
            foreach (IShape shape in slide.Shapes)
            {
                if (shape is IAutoShape)
                {
                    IParagraphCollection paragraphCollection = ((IAutoShape)shape).TextFrame.Paragraphs;
                    foreach (IParagraph para in paragraphCollection)
                    {
                        IPortion first = null;
                        IPortion last = null;
                        IPortionCollection portions = para.Portions;
                        for (int p = 0; p < portions.Count; p++)
                        {
                            IPortion portion = portions[p];
                            IPortionFormat portFormat = portion.PortionFormat;
                            // IPortionFormatEffectiveData portFormat = portion.CreatePortionFormatEffective();
                            //if (portFormat.FillFormat.SolidFillColor.Color == Color.Black)
                            if (portFormat.FillFormat.SolidFillColor.Color.R == 0 && portFormat.FillFormat.SolidFillColor.Color.G == 0
                                && portFormat.FillFormat.SolidFillColor.Color.B == 0)
                            {
                                if (first == null)
                                {
                                    first = portion;
                                }

                                last = portion;
                            }

                            if (((portFormat.FillFormat.SolidFillColor.Color.R == 255
                                //     if (((portFormat.FillFormat.SolidFillColor == Color.Red
                                              || (p == portions.Count - 1)) && first != null && last != null))
                            {
                                if (first == last)
                                {
                                    String portionText = first.Text;
                                    first.Text = "¤" + portionText + "¤";
                                }
                                else
                                {
                                    String firstPortionText = first.Text;
                                    String lastPortionText = last.Text;
                                    first.Text = "¤" + firstPortionText;
                                    last.Text = lastPortionText + "¤";
                                }

                                first = null;
                                last = null;
                            }
                        }
                    }
                }
            }
        }

        pres.Save(path + "text_replace2.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
    }