How to Underline Text in PDF Stamp using Java?

Thank you so much for support. Using non-cloud API we had the option to underline the text in a stamp using:
textStamp.getTextState().setUnderline(true);

I couldn’t find any such functionality using cloud API.
Is there any way i can underline the text using aspose-pdf-cloud?

@ahmedtariq

I am afraid currently Aspose.PDF Cloud does not provide Underline property in TextState. So we have logged a ticket PDFCLOUD-2623 for this purpose. We will notify you as soon as we resolve the issue. Meanwhile, please check PostPageUnderlineAnnotation API method to underline Text in PDF, if it fulfills your requirement.

POST ​/pdf​/{name}​/pages​/{pageNumber}​/annotations​/underline Add document page underline annotations.

How to Underline PDF Text in Java

import com.aspose.asposecloudpdf.ApiClient;
import com.aspose.asposecloudpdf.ApiException;
import com.aspose.asposecloudpdf.api.PdfApi;
import com.aspose.asposecloudpdf.model.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class UnderlineTextPDFCloudExamples {
    public static void main(String[] args) throws ApiException, IOException {
        //TODO: Get your ClientId and ClientSecret at https://dashboard.aspose.cloud (free registration is required)
        ApiClient apiClient = new ApiClient();
        apiClient.setAppKey("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        apiClient.setAppSid("xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx");

        // Initialize API
        PdfApi pdfApi = new PdfApi(apiClient);
        String name = "underlineText.pdf";
        int pageNumber = 1;

        Rectangle rect = new Rectangle()
                .LLX(100.)
                .LLY(100.)
                .URX(200.)
                .URY(200.);

        List<AnnotationFlags> flags = new ArrayList<>();
        flags.add(AnnotationFlags.DEFAULT);

        List<Point> points = new ArrayList<>();
        points.add(new Point().X(10.).Y(10.));
        points.add(new Point().X(20.).Y(10.));
        points.add(new Point().X(10.).Y(20.));
        points.add(new Point().X(10.).Y(10.));

        UnderlineAnnotation annotation = new UnderlineAnnotation();
        annotation.setName("Name");
        annotation.setRect(rect);
        annotation.setFlags(flags);
        annotation.setHorizontalAlignment(HorizontalAlignment.CENTER);
        annotation.setRichText("Rich Text");
        annotation.setSubject("Subj");
        annotation.setZindex(1);
        annotation.setTitle("Title");
        annotation.setQuadPoints(points);
        annotation.setModified("02/02/2018 00:00:00.000 AM");

        List<UnderlineAnnotation> annotations = new ArrayList<>();
        annotations.add(annotation);

        AsposeResponse underlinePDFTextResponse = pdfApi.postPageUnderlineAnnotations(name, pageNumber, annotations, null, null);
        System.out.println("completed......");
    }
}

Okay thanks, that works for my use case

1 Like

@ahmedtariq

About PDFCLOUD-2623, we have introduced the underline property in TextState. Please use the latest version of Aspose.PDF Cloud SDK for Java, it will help you to accomplish the underline text task.