How to Put a Line Through Text in PDF

In today’s digital landscape, the ability to programmatically apply strikethrough formatting to text within PDF documents is crucial. By leveraging Node.js and REST API, developers can seamlessly incorporate this feature into their applications. This article explores How to put a line through text in a PDF using Node.js and REST API, offering a concise guide for enhancing PDF manipulation capabilities.

Step 1: Installing Node.js Strikethrough Text Creator SDK

For strikethrough the text in PDF files, we will use the Node.js SDK of GroupDocs.Annotation Cloud API. It allows adding annotations, watermark overlays, text replacements, redactions, and text markups to the supported document formats. Please install it using the following command in the console:

npm install groupdocs-annotation-cloud

Step 2: Initialize the API Client

To initialize the API client, please get your Client ID and Client Secret from the dashboard and add the code as shown below:

/ This code example demonstrates how to add your client Id and Secret in the code.
global.clientId = "659fe7da-715b-4744-a0f7-cf469a392b73";
global.clientSecret = "b377c36cfa28fa69960ebac6b6e36421";
global.myStorage = "";
const configuration = new groupdocs_annotation_cloud.Configuration(clientId, clientSecret);
configuration.apiBaseUrl = "https://api.groupdocs.cloud";

Step 3: Uploading the Document

Before diving in, you need to upload the PDF document to which you want to make the strikeout text. Upload the document to the cloud storage using any of the following methods:

  • Using the dashboard.
  • Upload all files one by one using Upload File API from the browser.
  • Upload programmatically using the code example given below:
// This code example demonstrates how to upload a PDF file to the cloud.
// Initialize api instance
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Open file in IOStream from local/disc.
var resourcesFolder = 'C:\\Files\\Annotation\\sample.pdf';
// Read the file
fs.readFile(resourcesFolder, (err, fileStream) => {
// Upload file request
var request = new groupdocs_annotation_cloud.UploadFileRequest("sample.pdf", fileStream, myStorage);
// Upload file
fileApi.uploadFile(request);
});
view raw upload-file.js hosted with ❤ by GitHub

As a result, the uploaded files will be available in the [files section][https://dashboard.groupdocs.cloud/files] of your dashboard on the cloud.

Step 4: Strikethrough Text in PDF using Node.js SDK

The following steps and sample code shows how to strikethrough Text in a PDF using Node.js SDK.

  1. First, initialize the AnnotateApi instance using the provided client ID and client secret.
  2. Then, create a new AnnotationInfo object.
  3. Next, create four Point objects: p1, p2, p3, and p4, and set their x and y coordinates.
  4. Then, add the four points to the AnnotationInfo object.
  5. Next, set the page number for the annotation.
  6. Then, set the font color and font size for the annotation.
  7. Next, specify the annotation type as TextStrikeout and set the text content of the annotation.
  8. Then, set the creator name for the annotation.
  9. Next, create a new FileInfo object and set the file path to the input file.
  10. Then, create an AnnotateOptions object and set the FileInfo object and the AnnotationInfo object created above.
  11. Next, set the output path for the annotated file.
  12. Then, call the annotate method on the AnnotateApi instance with the AnnotateOptions object as a parameter and store the result in a variable.
  13. Finally, print the URL of the annotated file from the result to the console.

The following code example shows how to strike out Text in PDF using Node.js SDK.

// Initialize api instance
let annotateApi = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);
// Define annotation
let a1 = new annotation_cloud.AnnotationInfo();
// Point 1
let p1 = new groupdocs_annotation_cloud.Point();
p1.x = 30;
p1.y = 710;
// Point 2
let p2 = new groupdocs_annotation_cloud.Point();
p2.x = 460;
p2.y = 710;
// Point 3
let p3 = new groupdocs_annotation_cloud.Point();
p3.x = 30;
p3.y = 690;
// Point 4
let p4 = new groupdocs_annotation_cloud.Point();
p4.x = 460;
p4.y = 690;
// Add points
a1.points = [p1, p2, p3, p4];
// Page number
a1.pageNumber = 0;
// Font color
a1.fontColor = 65535;
a1.fontSize = 12;
// Specify annotation type as strikethrough
a1.type = annotation_cloud.AnnotationInfo.TypeEnum.TextStrikeout;
a1.text = "This is text strikeout annotation";
a1.creatorName = "Anonym A.";
// Input file
let fileInfo = new annotation_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
//Define annotation options
let options = new annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
// Define output file name
options.outputPath = "output.pdf";
// Annotate
let result = await annotateApi.annotate(new annotation_cloud.AnnotateRequest(options));
// Done
console.log("AddTextStrikeoutAnnotation: Text Strikeout Annotation added: " + result.href);
The output will be like the following screenshot:
Strikethrough in PDF

Step 5: Download Resultant File

The code given in the previous step saves the resultant file on the cloud. To download it, you can use the following code snippet.

// This code example demostrates how to download a PDF file from the cloud.
// Construct FileApi
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);
// Create download file request
let request = new groupdocs_annotation_cloud.DownloadFileRequest("output.pdf", myStorage);
// Download file
let response = await fileApi.downloadFile(request);
// Save file in your working directory
fs.writeFile("C:\\Files\\Annotation\\output.pdf", response, "binary", function (err) { });

FAQs:

How can I strikethrough text in a PDF using Node.js and REST API?

A: To strikethrough text in a PDF using Node.js and REST API, you can follow the steps as given above.

Can I customize the appearance of the strikethrough text annotation?

Yes, you can customize the appearance of the strikethrough text annotation. With the API, you can set properties such as the strikethrough text color and thickness. You can adjust these properties according to your requirements to achieve the desired visual effect.

Does the Node.js and REST API solution support batch processing of PDF documents?

Yes, the Node.js and REST API solution supports batch processing of PDF documents. You can pass multiple PDF files to the API and apply strikethrough text annotations to each document in the batch.

Is it possible to strikethrough text in specific pages of a PDF document?

Absolutely! You can specify the page numbers in the API request to apply strikethrough text annotations to specific pages of a PDF document.

Conclusion

In a nutshell, simplifying the process of adding strikethrough text annotations to PDFs is made possible by integrating Node.js with REST API. Utilize the strength of Node.js to improve your ability to annotate PDFs with strikethrough text.

Furthermore, you can see an API reference section that allows you to visualize and interact with our APIs directly through the browser. Node.js SDK’s complete source code is freely available on Github.

Finally, we keep writing new blog articles on different file formats and parsing them using REST API. So, please get in touch for the latest updates. Happy coding!

Free Online PDF Strikethrough Text Creator

To strikethrough text in a PDF online for free. Please try an online PDF strikethrough text maker app. This PDF text strikeout creator app is developed using the above-mentioned PDF strikethrough text creator REST API.

Ask a question

In case you would have any queries or confusion about the PDF strikethrough, please feel free to contact us via our forum.

See Also

Here are some related articles that you may find helpful: