How to Create a Vertical Line Annotation with Acrobat JavaScript
Question details
The user needs to create a perfectly straight vertical line annotation between two specific coordinates in a PDF using Acrobat JavaScript.

- Product
- 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.
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.
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.
Launch your PDF application and open the interactive JavaScript console to input your code.
Set up your script using the this.addAnnot object, ensuring you specify the correct page number and set the type to 'Line'.
Assign the exact X and Y coordinates using the points property format. For example: points: [[10, 10], [10, 100]].
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.

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. Open PDF File: Launch WPS Office and open the PDF document you want to annotate.
- 2. Access Comment Tools: Navigate to the 'Comment' tab located on the top navigation ribbon.
- 3. Select the Line Tool: Click on 'Shapes' or 'Draw' and choose the Line shape from the dropdown menu.
- 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. Save the Annotation: Customize the color or thickness if needed, then save the document to lock in the annotation.

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.




