We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Urgent: YIndent position is not accurate + Replace is not working correctly

Hi,

I am using Aspose.PDF for .Net on a Temp Developer license.

I am performing a search for word in a document and I need to know its correct X and Y coordinates.

The document is 612 x 792 dimensions.

The YIndents I received for desired word is offset by atleast 10 units away from the top margin.
How can I fix this or is this an expected behavior?

This is my output of the searched word.

Page: 1
Text : Hello
Position : ( 315.21398338, 697.014800132751 )
XIndent : 315.21398338
YIndent : 697.014800132751
Font - Name : TimesNewRomanPSMT
Font - IsAccessible : True
Font - IsEmbedded : True
Font - IsSubset : True
Font Size : 10
Foreground Color : #00

Hi there,


Thanks for your inquiry. Please share your source document, so we will look into it and will provide you more information accordingly.

Best Regards,

I attached the document - NDA.docx.pdf. The text {{signnow:signer1:text}} in the second line is what I need correct coordinates for.

I want to be able to replace that same {{signnow:signer1:text}} with a blank space to replace it with something else later on. The YIndent for this text is itself offset by a few units away from the heading.

When I did perform Search for the text using TextFragementAbsorber and printed out the textfragment details, I got the following for that Text {{signnow:signer1:text}}:

Page: 1
Text : {{signnow:signer1:text}}
Position : ( 90, 697.014800132751 )
XIndent : 90
YIndent : 697.014800132751
Font - Name : TimesNewRomanPSMT
Font - IsAccessible : True
Font - IsEmbedded : True
Font - IsSubset : True
Font Size : 10
Foreground Color : #00

I use my company’s internal API to place annotations on the document. To do that, I have to get the correct YIndent for positioning.
To get the actual YIndent, I subtracted 697 from 792 (as a document is 612X792). When I used this new YIndent = 95, I see the offset.

You can see the displaced annotation in the attached screenshot.

What is the correct way to deal with this YIndent issue?


Hi there,


Thanks for providing source documents. Please note measuring units of Aspose.Pdf is point and a 72 points=1 inch. You are getting correct XIndent and YIndent of text {{signnow:signer1:text}} on first page. However, we have noticed that API getting two occurrences on second page, whereas only one is visible. So we have logged a ticket, PDFNEWNET-36733, to investigate it further. We will keep you updated about our issue resolution progress.

Document document = new Document(myDir

  • “NDA.docx.pdf”);<o:p></o:p>

TextSearchOptions(true));

TextFragmentAbsorber textFragmentAbsorber1 = new TextFragmentAbsorber("{{_signnow_:signer1:text}}");

for (int cnt = 1; cnt <= document.Pages.Count; cnt++)

{

document.Pages[cnt].Accept(textFragmentAbsorber1);

TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber1.TextFragments;

foreach (TextFragment textFragment in textFragmentCollection1)

{

DefaultAppearance default_appearance = new DefaultAppearance("Arial", 12, System.Drawing.Color.Black);

FreeTextAnnotation freeText = new FreeTextAnnotation(document.Pages[cnt], new Aspose.Pdf.Rectangle((float)textFragment.Position.XIndent,

(float)textFragment.Position.YIndent, (float)textFragment.Position.XIndent + (float)textFragment.Rectangle.Width,

(float)textFragment.Position.YIndent + (float)textFragment.Rectangle.Height), default_appearance);

freeText.Border = new Border(freeText);

freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Transparent);

document.Pages[cnt].Annotations.Add(freeText);

Console.WriteLine("Page no. :{0}", cnt);

Console.WriteLine("Xindent:{0}",textFragment.Position.XIndent);

Console.WriteLine("Yindent:{0}", textFragment.Position.YIndent);

Console.WriteLine("Rect width:{0}", textFragment.Rectangle.Width);

Console.WriteLine("Rect Height:{0}", textFragment.Rectangle.Height);

}

}

//save updated document

document.Save(myDir + "testpostion_output.pdf");


Please feel free to contact us for any further assistance.

Best Regards,

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


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

Hi there,


In reference to above issue, we have investigated and found that using of nested loops isn’t correct in this case. Please, take into account ‘for’ loop adds to textFragmentAbsorber1.TextFragments collection all fragments that found on the page indexed ‘cnt’. But fragments that already exists in the collection remains in it. ‘Foreach’ loop marks all TextFragments in the collection but places marks on the page indexed ‘cnt’. But first TextFragment only on the first page not second. Above code marks first fragments twice.

So text TextFragmentAbsorber finds two occurrence of ‘signnow:signer1:text’ string in document.
For example this code returns two occurrences of searched text.

Document document = new Document(“NDA.docx.pdf”);<o:p></o:p>

TextSearchOptions
textSearchOptions = new TextSearchOptions(true);<o:p></o:p>

TextFragmentAbsorber
textFragmentAbsorber1 = new TextFragmentAbsorber("{{signnow:signer1:text}}");<o:p></o:p>

textFragmentAbsorber1.TextSearchOptions
= textSearchOptions;<o:p></o:p>

document.Pages.Accept(textFragmentAbsorber1);<o:p></o:p>

Console.WriteLine(textFragmentAbsorber1.TextFragments.Count);<o:p></o:p>

If we need to process a range of pages and get information about page number of some fragment then may use the following code.

Document document = new Document(inputFile);

TextSearchOptions textSearchOptions = new TextSearchOptions(true);

TextFragmentAbsorber textFragmentAbsorber1 = new TextFragmentAbsorber("{{_signnow_:signer1:text}}");

textFragmentAbsorber1.TextSearchOptions = textSearchOptions;

for (int cnt = 1; cnt <= document.Pages.Count; cnt++)

{

document.Pages[cnt].Accept(textFragmentAbsorber1);

}

TextFragmentCollection textFragmentCollection1 = textFragmentAbsorber1.TextFragments;

foreach (TextFragment textFragment in textFragmentCollection1)

{

DefaultAppearance default_appearance = new DefaultAppearance("Arial", 12, System.Drawing.Color.Black);

FreeTextAnnotation freeText = new FreeTextAnnotation(textFragment.Page, new Aspose.Pdf.Rectangle((float)textFragment.Position.XIndent,

(float)textFragment.Position.YIndent, (float)textFragment.Position.XIndent + (float)textFragment.Rectangle.Width,

(float)textFragment.Position.YIndent + (float)textFragment.Rectangle.Height), default_appearance);

freeText.Border = new Border(freeText);

freeText.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Transparent);

textFragment.Page.Annotations.Add(freeText);

Console.WriteLine(String.Format("Page no. :{0}", textFragment.Page.Number));

Console.WriteLine(String.Format("Xindent:{0}", textFragment.Position.XIndent));

Console.WriteLine(String.Format("Yindent:{0}", textFragment.Position.YIndent));

Console.WriteLine(String.Format("Rect width:{0}", textFragment.Rectangle.Width));

Console.WriteLine(String.Format("Rect Height:{0}", textFragment.Rectangle.Height));

}

//save updated document

document.Save(outputFile);

</o:p>

<o:p> </o:p>

<o:p>Please feel free to contact us for any further assistance.</o:p>

<o:p>
</o:p>

<o:p>Best Regards,</o:p>