PDF Editing Issues

How to Create a Vertical Line Annotation with Acrobat JavaScript

Emma BrownEmma Brown Nov 5, 2026 870 views

Question details

The user needs to create a perfectly straight vertical line annotation between two specific coordinates in a PDF using Acrobat JavaScript.

How to Create a Vertical Line Annotation Using Acrobat JavaScript
Product
PDF
Device & OS
not provided
Scenario
Writing a JavaScript macro or script to programmatically add line annotations to a PDF document.
Observed behavior
When using the rect property, the line annotation is generated at an unexpected angle instead of forming a clean, vertical line.
Before you start

Ensure you have access to the JavaScript console in your PDF editor and understand the basic X and Y coordinate system used for PDF page formatting.

Solution 1Recommended

Use the Points Property for Line Annotations

Replace the rect property with the points property to precisely control the start and end coordinates of the line.

The rect property defines a bounding box for an annotation rather than a directional path. When a line is placed inside a bounding box, it draws diagonally from corner to corner, often resulting in an unexpected angle.

To draw a precise line, you must use the points property, which explicitly sets the starting and ending coordinate pairs.

1
Open the JavaScript Console

Launch your PDF application and open the interactive JavaScript console to input your code.

2
Define the addAnnot Method

Set up your script using the this.addAnnot object, ensuring you specify the correct page number and set the type to 'Line'.

3
Implement the Points Array

Assign the exact X and Y coordinates using the points property format. For example: points: [[10, 10], [10, 100]].

4
Execute the Script

Run the completed code: var bhd = this.addAnnot({ name: "FR", page: this.pageNum, type: "Line", points: [[10, 10], [10, 100]] }); to generate the vertical line.

Use the Points Property for Line Annotations
Keeping the Line Vertical: To ensure the line is perfectly vertical, the first X coordinate and the second X coordinate in your points array must be identical (e.g., the '10' in both [10, 10] and [10, 100]).

Easily Add Vertical Lines and Annotations Visually in WPS PDF

If writing JavaScript code is too time-consuming, you can quickly draw perfect vertical lines and add various custom annotations using WPS Office's built-in PDF editing tools, with no programming required.

  1. 1. Open PDF File: Launch WPS Office and open the PDF document you want to annotate.
  2. 2. Access Comment Tools: Navigate to the 'Comment' tab located on the top navigation ribbon.
  3. 3. Select the Line Tool: Click on 'Shapes' or 'Draw' and choose the Line shape from the dropdown menu.
  4. 4. Draw a Vertical Line: Hold down the Shift key on your keyboard and drag your mouse vertically to automatically snap the line to a perfect 90-degree angle.
  5. 5. Save the Annotation: Customize the color or thickness if needed, then save the document to lock in the annotation.
Visual drag-and-drop line annotation toolsNo JavaScript programming knowledge requiredFully compatible with standard Adobe PDF formatsLightweight software with an intuitive, user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does the rect property cause lines to be drawn at an angle?

The rect property defines a rectangular bounding box. When a line is assigned to a rect, the application draws it diagonally from one corner of the box to the opposite corner. If the box isn't perfectly proportioned, the line will appear angled.

Can I change the color and thickness of the line via JavaScript?

Yes, you can customize the appearance by adding properties like strokeColor (e.g., strokeColor: color.red) and width (e.g., width: 2) within the this.addAnnot object parameters.

How do I determine the exact coordinates for the points array?

In standard PDF coordinate systems, the origin point (0,0) is located at the bottom-left corner of the page. X increases to the right, and Y increases upwards. You can use cursor coordinate displays or measurement tools in your PDF editor to find the exact target points.