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 Apr 22, 2021 7:08 pm

textalignment.zip
textalignment.zip
I have a template with textbox placeholder.I need to ad text this placeholder and align it center.(code below).The below code is working fine in my system(windows 10) but when i move to the server (linux) the text is aligned to left by default.when i clickk on the text thhe text gets center aligned.otherwise left aligned

if (field instanceof PdfTextBoxFieldWidget) {

PdfTextBoxFieldWidget textBoxField = (PdfTextBoxFieldWidget) field;
PdfTextAlignment align = textBoxField.getTextAlignment();

if(textBoxField.getName().equalsIgnoreCase("Insert Start date")){
Dimension2D dim = textBoxField.getSize();
textBoxField.setSize(dim);
textBoxField.setText(fileConversionDto.getCta1());
textBoxField.setTextAlignment(align);
textBoxField.setFlatten(true);

}

Chithram
 
Posts: 2
Joined: Thu Apr 01, 2021 11:17 am

Fri Apr 23, 2021 10:51 am

Hello,

Thanks for your inquiry.
Please refer to the following code to set the alignment first, and then fill in the text. I have verified that it works fine on my side.
Code: Select all
         if(textBoxField.getName().equalsIgnoreCase("Insert Start date")){
                Dimension2D dim = textBoxField.getSize();
                textBoxField.setSize(dim);
               //textBoxField.setText(fileConversionDto.getCta1());
                //textBoxField.setTextAlignment(align);
                textBoxField.setTextAlignment(align);
                textBoxField.setText(fileConversionDto.getCta1());
                textBoxField.setFlatten(true);
            }

If there are any issues, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Apr 23, 2021 12:01 pm

Thanks for your assitance.
I updated the code accordingly ,but the issue still exists.PFA screenshot..
THe first place holder looks centre aligned and the second text is left aligned.Though the alignment property for both the fields are "centre".
If I set the text to "click for info" ion both the fields then both the fields are left aligned.Does this alignmnt have anything to do with the string length..cause smaller text less than 8 charaacters looks aligned properly.
I even tried setReadOnly(true)..

if(textBoxField.getName().equalsIgnoreCase("Insert Start date")){
Dimension2D dim = textBoxField.getSize();
textBoxField.setSize(dim);
textBoxField.setTextAlignment(align);
textBoxField.setText(fileConversionDto.getCta1());
textBoxField.setMaxLength(15);
textBoxField.setFlatten(true);

}
if(textBoxField.getName().equalsIgnoreCase("URL")){
Dimension2D dim = textBoxField.getSize();
textBoxField.setSize(dim);
textBoxField.setTextAlignment(align);
textBoxField.setText(fileConversionDto.getCta2());
textBoxField.setMaxLength(15);
textBoxField.setFlatten(true);


}

Chithram
 
Posts: 2
Joined: Thu Apr 01, 2021 11:17 am

Sun Apr 25, 2021 6:12 am

Hello,

Thanks for your feedback.
To help us investigate your issue more accurately and quickly, please provide us with your input file. You could send it to us ([email protected]) via email. Thanks in advance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Apr 26, 2021 2:43 am

Hello,

Thanks for providing your input file via email.
I tested your case and did reproduce your issue. I have logged it in our bug tracking system with the ticket SPIREPDF-4244. If there is any update, we will inform you immediately. Apologize for the inconvenience caused.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF

cron