Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:43:27+00:00 2026-06-10T09:43:27+00:00

I using the below code to print a string in pdf which give me

  • 0

I using the below code to print a string in pdf which give me an out put of the same sized string i want to make the last two string in different font size. how can i do this ?

PdfContentByte cb = writer.getDirectContent();

    String stl = "", stl1 = (String) request.getParameter("x0");//                        (String)val.get(0);
        int ln = stl1.length();
        String new1 ="" ;
        if (ln > 1)
        {
            for (int ii = 0; ii < ln - 2; ii++)
                stl = stl + stl1.charAt(ii);
            stl = stl + " . ";
            stl1 = stl1.substring(ln - 2, ln);
            new1 = stl + stl1;
            //stl1 = stl + stl1;

        }
        cb.setFontAndSize(bf, 18); 
        cb.setTextRenderingMode(2);
        //cb.showTextAligned(PdfContentByte.ALIGN_LEFT, stl1, 20 + x, 663 + y, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_LEFT, new1, 20 + x, 663 + y, 0);

Desired Output :

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:43:28+00:00Added an answer on June 10, 2026 at 9:43 am

    The best way to do this is to print a separate string after the first one that contains the last 2 digits.

    Code example:

    1) Replace String new1 ="" ; with this:

    String textLarge ="" ;
    String textSmall ="" ;
    

    2) Replace new1 = stl + stl1; with the following:

    textLarge = stl;
    textSmall = stl1;
    

    3) Change some code to print the large and small text separately

    cb.setFontAndSize(bf, 18);        
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, textLarge, 20 + x, 663 + y, 0);
    cb.setFontAndSize(bf, 14);        
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, textSmall, 20 + ? + x, 663 + y, 0);
    

    Replace the “?” in the line above with the printed width of large text.
    It looks like you are using itext, so you can use either:
    BaseFont.getWidthPoint(String text, float fontSize) to get the width of the string in pt.
    Or put the string in a Chunk and do chunk.getWidthPoint()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the example below, if client code using GetPeople wanted to print the name
Currently i'm using below code which works well. $(#topperAtBaseLevel:visible, #lowerAtBaseLevel:visible, #midAtBaseLevel).hide(); any optimised code?
I am using the code below to get a string in Java to use
I am currently using the below code to run a process and print its
I am using the below code to take print screen of my web page.
Trying to only print if a string isn't empty, and am using the code
I am currently using the below code for printing a pdf using Foxit Reader
Is unique_ptr thread safe? Is it impossible for the code below to print same
I am using the below code to print an image from my C# code.
I am using this code for comparing string values in a method, which work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.