Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu May 04, 2023 11:20 am

Hi

I've been asked to create a vb.net program to stamp some text on a series of pdfs, but the stamped text has to use same colour as an existing piece of text on the pdf (which can vary in colour).

Is it possible to detect text colour?

I've done some basic testing by loading in the pdf and using PdfTextFind, which gives me position of the text I need to match to (which is very useful), but I don't think I can get the colour from this method as I was hoping to.

Any advice gratefully received - thanks!

Ash_Precision2
 
Posts: 9
Joined: Mon Jun 14, 2021 9:17 am

Fri May 05, 2023 2:23 am

Hi,

Thanks for your inquiry.
Sorry our Spire.PDF doesn't support getting the text color at present. We will consider adding it into our upgrade list, if it is available in the future, I will notify you immediately.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri May 05, 2023 9:08 am

Ah! OK, no worries I thought I'd seen some reference to being able to do this somewhere.

Hopefully it will come along in future.

Have a good day!

Ash_Precision2
 
Posts: 9
Joined: Mon Jun 14, 2021 9:17 am

Fri May 05, 2023 9:24 am

Hi,

Thanks for your understanding, once the new feature is implemented, I will inform you. Sorry for the inconvenience caused.

Have a nice day!

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri May 05, 2023 10:53 am

Hi

There might be a workaround - I see that Spire can convert pdf to postscript.

If I can create a pdf with just the colour I want on it (so I don't get multiple colours to work with), it should be possible to open the ps file as text and search for the cmyk value with some regex.

It's a horrible kludge, but I'll see how far I get!

Ash_Precision2
 
Posts: 9
Joined: Mon Jun 14, 2021 9:17 am

Sat May 06, 2023 3:08 am

Hi,

Thanks for your feedback.
If you have any further questions or concerns regarding the use of our product, please don't hesitate to ask. We are always here to help.

Good luck to you!

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Apr 24, 2024 5:48 am

Hi,

Thank you for your patience.

I'm glad to inform you that our Spire.PDF has supported retrieving font formatting of found text. Note: Only supports retrieving bold, faux bold (font style set to fill and stroke), italic, and color;

Welcome to download and test [Spire.PDF Pack(Hot Fix) Version:10.4.7].
Our website link:https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
NuGet link: https://www.nuget.org/packages/Spire.PDF

Code: Select all
 PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(inputFile);
            PdfPageBase page = pdf.Pages[0];
            PdfTextFinder finds = new PdfTextFinder(page);
            finds.Options.Parameter = TextFindParameter.None;
            List<PdfTextFragment> result = finds.Find("hello");
            StringBuilder str = new StringBuilder();
            foreach (PdfTextFragment find in result)
            {
                string text = find.LineText;
                string FontName = find.TextStates[0].FontName;
                float FontSize = find.TextStates[0].FontSize;
                string FontFamily = find.TextStates[0].FontFamily;
                bool IsBold = find.TextStates[0].IsBold;
                bool IsSimulateBold = find.TextStates[0].IsSimulateBold;
                bool IsItalic = find.TextStates[0].IsItalic;
                Color color = find.TextStates[0].ForegroundColor;
                str.AppendLine(text);
                str.AppendLine("FontName: " + FontName);
                str.AppendLine("FontSize: " + FontSize);
                str.AppendLine("FontFamily: " + FontFamily);
                str.AppendLine("IsBold: " + IsBold);
                str.AppendLine("IsSimulateBold: " + IsSimulateBold);
                str.AppendLine("IsItalic: " + IsItalic);
                str.AppendLine("color: " + color);
                str.AppendLine(" ");
            }
            PdfTextReplacer ptr = new PdfTextReplacer(page);
            ptr.ReplaceAllText("hello", "New");
            File.WriteAllText(outputFile_T, str.ToString());
            pdf.SaveToFile(outputFile);
            pdf.Dispose();


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF

cron