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.

Tue Feb 14, 2023 9:55 am

Hi , we are using Spire.Doc 11.1.0 and Spire.Pdf 9.1.0 licensed versions.
We need to be able to replace string in document and for that we are using this code:

PdfTextReplacer replacer = new PdfTextReplacer(page);
replacer.ReplaceText(text, replaceStr);

we created replace string concerning char "~" in width of string that we found for replacement.

Usually replacement is well but sometimes it is making text after replacement wrong , I will send file before and after replacement so you can test it.
Regards

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

Wed Feb 15, 2023 3:22 am

Hi,

Thanks for your feedback.
I tested your document and reproduced your issue, I have logged this issue into our bug tracking system with the ticket number SPIREPDF-5785, our developers will investigate and fix it. Sorry for the inconvenience caused. Once the issue is fixed, I will inform you asap.

Sincerely,
Triste
E-iceblue support team
User avatar

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

Thu Mar 16, 2023 1:51 pm

Was there any progress on this issue?

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

Fri Mar 17, 2023 1:30 am

Hi,

Thanks for your following-up.
We would like to inform you that we are currently in the process of submitting the code changes for this issue, but we have not yet completed testing. Our developers are working diligently to resolve this issue as quickly and efficiently as possible. Thanks for your understanding. Once there are any updates available, I will inform you asap.

Best regards,
Triste
E-iceblue support team
User avatar

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

Fri Apr 07, 2023 1:35 am

Hi,

Thanks for your patience.
Glad to inform you that we just released Spire.PDF 9.4.0 hotfix, which fixed your issue SPIREPDF-5785, please download from the following links and have a test.
Website link: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/9.4.0

Best regards,
Triste
E-iceblue support team
User avatar

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

Thu Sep 14, 2023 9:05 am

I have downloaded the latest Spire.Pdf 9.9.3 and Spire .Doc 11.8.18 document and this error happens again.
It seams that we are going in to circles with resolving errors.

Please check this error again.
Regards

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

Fri Sep 15, 2023 1:36 am

Hi,

Thanks for your feedback.
I created a simple console project to retest your document, using the latest Spire.PDF_9.9.3, but I did not reproduce your issue. I have attached my result document for your reference.
result.png

we suggest that you create a simple project to test it again, if the issue still exists, please share us with your test environment, so that we can investigate further. Thanks for your understanding and assistance.

Best regards,
Triste
E-iceblue support team
User avatar

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

Thu Nov 30, 2023 10:34 am

We still have this issue , I am sending document that you can test on an code where we convert doc to pdf and find some sentences and then replace it with sting made of "~" in the same width as the sentence that we replacing .Also I am sending the pdf product after code.

Code:
Document doc =new Document();
PdfDocument doc1 = new PdfDocument();
MemoryStream memoryStream1 =new MemoryStream();
doc.LoadFromFile(@"root...\file-sampleBefore.doc");
ToPdfParameterList pdf2 = new ToPdfParameterList()
{
IsEmbeddedAllFonts = true
};
pdf2.DisableLink = false;
pdf2.UsePSCoversion = true;
doc.SaveToStream(memoryStream1, pdf2);
doc1.LoadFromStream(memoryStream1);
List<string> dictionary = new List<string> { "dapibus", "viverra" , "In non mauris justo.Duis vehicula mi vel mi pretium, a viverra erat
efficitur.viverra Mauris id", "Mauris id ex erat.", "Maecenas" };
PdfTextFindOptions findOptions = new PdfTextFindOptions();
findOptions.Parameter = TextFindParameter.WholeWord | TextFindParameter.IgnoreCase;
dictionary = dictionary.OrderByDescending(x => x.Length).ToList();
int i = 0;
PdfFont font1;
foreach (string word in dictionary)
{
foreach (PdfPageBase page in doc1.Pages)
{
i++;

PdfTextFinder finder = new PdfTextFinder(page);
finder.Options = findOptions;
List<PdfTextFragment> result = finder.Find(word);
PdfTextReplacer replacer = new PdfTextReplacer(page);
replacer.Options.ReplaceType = PdfTextReplaceOptions.ReplaceActionType.AutofitWidth;
if (result.Count() > 0)
{

foreach (PdfTextFragment findWord in result)
{

font1 = new PdfFont(PdfFontFamily.Helvetica, findWord.Sizes[0].Height);
PdfStringFormat format = new PdfStringFormat();

SizeF sizeOne = font1.MeasureString("~", format);

int count = (int)(findWord.Bounds[0].Width / sizeOne.Width);
if (count == 0) count = 1;

string replaseStr = String.Concat(Enumerable.Repeat("~", count));
SizeF sizereplace = font1.MeasureString(replaseStr, format);
while ((findWord.Bounds[0].Width - sizeOne.Width) > sizereplace.Width)
{
replaseStr = replaseStr + "~";
sizereplace = font1.MeasureString(replaseStr, format);
}

try
{

replacer.ReplaceText(findWord.Text, replaseStr);

}
catch (Exception ex)
{

}
}
}
}
}
doc1.SaveToFile(@"root..\file-sampleAfter.pdf");

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

Fri Dec 01, 2023 3:08 am

Hi,

Thanks for your feedback.
I have reproduced this issue and logged it into our issue tracking system with the ticket number SPIREPDF-6426. We apologize for any inconvenience caused. I gave this issue the highest priority and urged our developers to resolve it as quickly as possible. Once the issue is fixed, I will inform you immediately. Thanks for your cooperation and understanding.

Best regards,
Triste
E-iceblue support team
User avatar

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

Mon Jan 29, 2024 9:55 am

Hi,

Thank you for your patience.

We are pleased to inform you that we have addressed this issue SPIREPDF-6426 in the latest version of our Spire.PDF. We recommend downloading the new version and conducting tests to verify the resolution. Please let us know if you encounter any further difficulties or if you require any assistance while testing the updated version.
Additionally, we would like to suggest using the same font as the original document when replacing text. This will help ensure a better outcome

Website:https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget:https://www.nuget.org/packages/Spire.PDF/10.1.17

Best regards,
Triste
E-iceblue support team
User avatar

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

Return to Spire.PDF