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.

Fri Dec 23, 2022 9:15 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.Office 7.12.4 which fixes the issue with SPIREPDF-5597 .
Please download the new version from the following links to test.

Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Office/7.12.4

Sincerely
Abel
E-iceblue support team
User avatar

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

Fri Jan 20, 2023 4:52 pm

When we replace word with replacer we can experience a lot of blanks after word even thought the new word is created to be same size as the replaced word, do you know why this is happening and do you have any solution to suggest ?

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Mon Jan 23, 2023 5:45 am

Hello,

Thanks for your inquiry.
I did an initial test with the last version(Spire.Office Platinum(Hotfix) Version:8.1.1), but did not reproduce your issue. Are you testing the latest version? If not, please use the latest version of the test first. If the issue still exists after testing, please provide the following information for further investigation. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
1) Your PDF document and your code.
2) Your test Environment, such as Windows10, 64bit.
3) The type of application, such as Console App, .NET Framework 4.8.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Jan 23, 2023 9:59 am

Hi We are using only 2 dell's Spire.Doc 11.1.0 and Spire.Pdf 9.1.0 this is the latest release that fix our other issue. When we are doing replace in pdf documents we are reading what is the original font of the word and then replace it with new word with same font and same size width. can you send me code that you use for replace so that I can try it with files that I have test with?

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Tue Jan 24, 2023 6:44 am

Hello,

Thank you for your feedback.
Please refer to my code below. The reason why the new text is not drawn is that the newly set font size is larger than the size of the original text (this line of code: PdfTrueTypeFont font=new PdfTrueTypeFont (new Font ("Arial", 10f, FontStyle. Regular);). In this way, the text length of the new text is greater than the length of the old text, so the drawing will fail. Please reduce the font size to draw.
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("input.pdf");

PdfPageBase page = doc.Pages[0];

PdfTextFindCollection collection = page.FindText("Text", Spire.Pdf.General.Find.TextFindParameter.IgnoreCase);

String newText = "Test";

PdfBrush brush = new PdfSolidBrush(Color.Black);
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Regular));

RectangleF rec;
foreach (PdfTextFind find in collection.Finds)
{
    rec = find.Bounds;
    page.Canvas.DrawRectangle(PdfBrushes.White, rec);
    page.Canvas.DrawString(newText, font, brush, rec);
}

doc.SaveToFile("result.pdf");

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Jan 24, 2023 11:20 am

We are using PdfTextReplacer for really replace text in pdf so it can't be read any more by for example copying it to text file.
When we calculate new replace word we are getting the font and size of word that we find in text and calculate replace word based by that and then we can see white spaces.
We cant use page.Canvas.DrawString(newText, font, brush, rec); because it is not realy replacing word. Also we could see that 'Spire.Pdf.General.Find.TextFindParameter.IgnoreCase' da not work as regular ignore case , because it is finding only words with first capital letter+small letters and all small letters, it das not find word with camelCase and all Big letters.
we are using code :

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("input.pdf");

PdfPageBase page = doc.Pages[0];

foreach (PdfPageBase page in doc.Pages)
{
PdfTextFind[] result = page.FindText(word, Spire.Pdf.General.Find.TextFindParameter.IgnoreCase).Finds;
foreach (PdfTextFind res in result) {
Font font1 = new Font(res.FontName, res.Size.Height);

Image fakeImage = new Bitmap(1, 1);
Graphics graphics = Graphics.FromImage(fakeImage);
SizeF size1 = graphics.MeasureString(word, font1,res.Size);

SizeF size2 = graphics.MeasureString("▪", font1, size1);
int count = (int)(size1.Width / size2.Width);
if (count == 0) count = 1;

string replaseStr = String.Concat(Enumerable.Repeat("▪", count));
replacer.ReplaceText(word, replaseStr);

}
doc.SaveToFile("result.pdf");

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Wed Jan 25, 2023 2:42 pm

Hello,

Thanks for your inquiry.
After preliminary test, I did notice the issue of white space, I also did notice the issue of of not being able to copy the replaced text into the txt file. I need to communcite with our Dev team to work out a solution for you, however, due to we are now having our Spring Festival holiday from 21/01/2023 to 27/01/2023 (GMT+8:00), I can't give you a solution for the moment. Once there are any updates about this issue, I'll inform you in time.

In addition, I didn't reproduce these issue of not finding word with camelCase and all Big letters when I using the latest version of Spire.Pdf 9.1.0and the following code to test your scenario. I also attached the result pdf file for your reference.


Code: Select all
 PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"../../data/input.pdf");

            //PdfPageBase page = doc.Pages[0];

            foreach (PdfPageBase page in doc.Pages)
            {
                string word = "aBel";
                PdfTextFind[] result = page.FindText(word, Spire.Pdf.General.Find.TextFindParameter.IgnoreCase).Finds;
                foreach (PdfTextFind res in result)
                {
                    Font font1 = new Font(res.FontName, res.Size.Height);

                    Image fakeImage = new Bitmap(1, 1);
                    Graphics graphics = Graphics.FromImage(fakeImage);
                    SizeF size1 = graphics.MeasureString(word, font1, res.Size);

                    SizeF size2 = graphics.MeasureString("▪", font1, size1);
                    int count = (int)(size1.Width / size2.Width);
                    if (count == 0) count = 1;

                    string replaseStr = String.Concat(Enumerable.Repeat("▪", count));
                    PdfTextReplacer replacer = new PdfTextReplacer(page);

                    replacer.ReplaceText(word, replaseStr);

                }
                doc.SaveToFile(@"../../output/input_result111.pdf");
User avatar

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

Wed Jan 25, 2023 3:27 pm

Regarding second issue I don't understand your replay. If we use in page.FindText(word, TextFindParameter.IgnoreCase ).Finds with the parametar TextFindParameter.IgnoreCase shuldn't that mean that we need to find every version of word no matter which letters are big and which are small.
Fore example my test was using word "Onelog" and page.FindText result find "Onelog" and "onelog" but did not find "ONELOG" or "oneLog", and what we expected like in any other programs when we say to Ignorecase is to find any version of the word.
I'm sending file that I have tested on Ignore case scenario word="Onelog".

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Thu Jan 26, 2023 2:16 am

Hello,

Thanks for your feedback.
After further investigation, I did notice the issue and I'll report it to our Dev team after Spring Festival holiday. Sorry for the inconvenience caused.

Sincerely
Abel
E-iceblue
User avatar

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

Sat Jan 28, 2023 7:07 am

Hello,

Thanks for your patient waiting.
After further investigation, for the issue not finding word with camelCase and all Big letters, I found that word with camelCase and all Big letters can be found when I debug the application, but when you call the “Replace” method, you only replace “word”, as the following code you provided:
Code: Select all
replacer.ReplaceText(word, replaseStr);

You need to change the code to :
Code: Select all
replacer.ReplaceText(res.MatchText, replaseStr);

In addition, I can copy the replaced text to txt file when I use the Adobe acrobe to open the result file. According to the Pdf file (Ignorecase-after.pdf), I didn’t find the issue of white spaces. To help us do further investigation, please offer your input file and output file, you can attach here or send it to us via email ([email protected]). Thanks for your assistance in advance.

Sincerely
Abel
E-iceblue support team
User avatar

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

Tue Jan 31, 2023 11:19 am

Thank you for replay , it das work like this. I have additional question is it possible to combine TextFindParameter like this TextFindParameter.IgnoreCase| TextFindParameter.WholeWord and is that mean that we should find all whole word with small and big letters?

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Wed Feb 01, 2023 2:09 am

Hello,

Thanks for your feedback.
Yes, your understanding is correct.
If you have any issue in test phase, just feel free to contact us.

Sincerely
Abel
E-iceblue support team
User avatar

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

Wed Feb 01, 2023 12:13 pm

Hi,

I have tested on document with one line
"Onelogadd is onelog is oneLogxxx Is ONELOG"
to try to find word "onelog" with PdfTextFind[] result = page.FindText(word, TextFindParameter.IgnoreCase&TextFindParameter.WholeWord).Finds;
and it das not find only one word "onelog" like it das not aply ignor case also if I try to find word "Onelog" it finds only "Onelogadd" even it is not a whole word.
Can you please advise me is it possible to combine parameters and how?

If I try to find word "onelog" with PdfTextFind[] result = page.FindText(word, TextFindParameter.IgnoreCase | TextFindParameter.WholeWord).Finds; it is again all wrong.

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Thu Feb 02, 2023 9:13 am

Hi,

Thanks for your feedback.
I simulated a pdf document with a line of words “Onelogadd is onelog is oneLogxxx Is ONELOG”,if we add the ignoreCase and WholeWord parameters then search text (“onelog”), the result should be like the following picture shown.
sample.png

page.findText(string searchPatternText, bool isSearchWholeWord, bool ignoreCase) is deprecated. I did some tests with our new interface: PdfTextFinder, it works fine, please see the following code for reference.
Code: Select all
PdfDocument pdf = new PdfDocument();
//Load a PDF file
pdf.LoadFromFile("test.pdf");

//Creare a PdfTextFindOptions instance
PdfTextFindOptions findOptions = new PdfTextFindOptions();

//Specify the text finding parameter
findOptions.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord | Spire.Pdf.Texts.TextFindParameter.IgnoreCase;
PdfPageBase page = pdf.Pages[0];
PdfTextFinder finder = new PdfTextFinder(page);
//Set the text finding option
finder.Options = findOptions;
//Find a specific text
List<PdfTextFragment> results = finder.Find("onelog");

debug.png

If you have further questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

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

Wed Feb 08, 2023 4:36 pm

Thank you this issue is closed with new function for search text.
Regards
Biljana.

bstojanovic
 
Posts: 45
Joined: Mon Sep 28, 2020 2:54 pm

Return to Spire.PDF

cron