PDF right alignment issue for variables

Hi ,

We are replacing variables with some string values in PDF file. All these variables are right aligned. But in generated PDf, the value of the variables are not properly aligned.
Can you please help how to fix it.
BaseNonQC_EN_Template.pdf (982.4 KB)

                    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(rf.PolicyKEY);
                    Doc.Pages.Accept(textFragmentAbsorber);
                    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
                    foreach (TextFragment textFragment in textFragmentCollection)
                    {
                        textFragment.Text = rf.PolicyValue.Trim();

}

Here is the code to replace variable values. i have attached the file with variables. I am getting this issue on 2nd page of PDF.ContinYouGOLDEN_Policy_Joey Tribiani_April_1_2021.pdf (973.7 KB)

I have attached generated PDF. In 2nd page
Retiree: Joey Tribiani
Policy Number: G65001
Certificate Number: 0000213500
Effective Date: March 01, 2021
Annual Renewal Date: January 1

I want all the above paragraph right aligned. Please help to fix this issue.

@sapnajain5

Can you please share code for rf.PolicyKEY and rf.PolicyValue as apparently when I try to replace the textFragment.Text the horizontal alignment remains as Left.

I am getting values of rf.PolicyKEY and rf.PolicyValue from Stored Procedure and storing it in PolicyReplacement List class.

public class PolicyReplacement
{
public string PolicyKEY { get; set; }
public string PolicyValue { get; set; }

}

Below is my select query in SP to get policyKEy and PolicyValue

SELECT '<<Name>>', @FName + ' '+ @LName UNION ALL 
	SELECT '<<AcNo>>',@AcNo  UNION ALL 
	SELECT '<<CerNum>>',@CertNo  UNION ALL 
	SELECT '<<EffecDate>>', DATENAME(MM, @EffecDate) + RIGHT(CONVERT(VARCHAR(12), @EffecDate, 107), 9) UNION ALL
	SELECT '<<EffecDateFr>>',  @EffecDateFr UNION ALL
	SELECT '<<Max_dur>>', @Max_dur 

You can add following hard coded list items in PolicyReplacement List class.

  1. rf.PolicyKEY = " <>", rf.PolicyValue = “any name”
  2. rf.PolicyKEY = " <>", rf.PolicyValue = “0000213500”
  3. rf.PolicyKEY = " <>", rf.PolicyValue = “March 01, 2021”

foreach (PolicyReplacement rf in PolicyReplacement)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(rf.PolicyKEY);
Doc.Pages.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
{
textFragment.Text = rf.PolicyValue.Trim();
}

Please let me know if you need more information.

@sapnajain5

Thank you for sharing the information. I have shared the generated PDF and console output with you. The text alignment remains on Left even we change the text. The API is performing as it is suppose to behave. Can you please share the output that is desired. For your convenience, I have also attached the sample code that I have used to carryout testing on my end.

public class PolicyReplacement
{
    public string PolicyKEY { get; set; }
    public string PolicyValue { get; set; }
    public PolicyReplacement(string _PolicyKey,string _PolicyValue)
    {
        PolicyKEY = _PolicyKey;
        PolicyValue = _PolicyValue;
    }

}
public static void TestReplaceText()
    {

        List<PolicyReplacement> list = new List<PolicyReplacement>();
        list.Add(new PolicyReplacement("<<Name>>", "Joey Tribiani"));
        list.Add(new PolicyReplacement("<<CerNum>>", "0000213500"));
        list.Add(new PolicyReplacement("<<EffecDate>>", "March 01, 2021"));

        using (var Doc = new Aspose.Pdf.Document(path + "BaseNonQC_EN_Template.pdf"))
        {
            foreach (PolicyReplacement rf in list)
            {
                TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(rf.PolicyKEY);
                Doc.Pages.Accept(textFragmentAbsorber);
                TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
                foreach (TextFragment textFragment in textFragmentCollection)
                {

                    Console.WriteLine($"Before Text: {textFragment.Text} with Alignment: {textFragment.HorizontalAlignment.ToString()}");
                    textFragment.Text = rf.PolicyValue.Trim();
                    Console.WriteLine($"After Text: {textFragment.Text} with Alignment: {textFragment.HorizontalAlignment.ToString()}");
                }
            }
            Doc.Save(path + "test_snippet_3.pdf");
        }
    }

Can you please share the desired output that you are expecting to get using API.

test_snippet_3.pdf (1006.9 KB)
Console Output.pdf (39.0 KB

Hi ,

I want below data on 2nd page of PDF should be right aligned.

             Retiree: Joey Tribiani 
         Policy Number: G65001 

Certificate Number: 0000213500
Effective Date: March 01, 2021
Annual Renewal Date: January 1

Please find the attached PDF and check 2nd page of PDF. This is what we want in an output PDF.

ContinYouGOLDEN_Policy_Joey Tribiani_March_31_2021 (17).pdf (859.7 KB)

@sapnajain5

After careful investigation of requirement, it seems to be an issue and we need to further investigate it, as despite setting alignment to Right it is not getting applied. A ticket with ID PDFNET-49702 has been created to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Hi,

Any update on this. Please let me know if you find any solution.

@sapnajain5

I regret to share that the issue has just recently been added in our issue tracking system and is pending for investigation in issues queue. We request for your patience and will share the good news with you as soon as it will be shared by our team.