# XY coordinate issue for some documents

**URL:** <https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534>\
**Category:** Technical Support\
**Created:** [April 21, 2023, 1:21pm UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534 "2023-04-21T13:21:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [April 21, 2023, 1:21pm UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/1 "2023-04-21T13:21:31Z")

</div>

PDF express version : 8.4

We are programmatically adding a free text annotation with every text annotation. For that we are using annotation change event. In that event, we create a free text annotation and place it at the bottom using XY coordinates of the annotation.

const freeText = new Annotations.FreeTextAnnotation();  
var timeStamp = serverTime ? serverTime : moment().format(“MM-DD-YYYY HH:mm:ss”);  
freeText.PageNumber = PageNumber; [//el.PageNumber](https://el.PageNumber);  
freeText.X = X; [//el.LeftMost](https://el.LeftMost);  
freeText.Y = Y + Height; [//el.BottomMost](https://el.BottomMost);  
freeText.Width = authorWidth;  
freeText.Height = authorHeight;  
freeText.setContents(userObj.nickname + “\n” + timeStamp);  
freeText.FontSize = “12pt”;  
freeText.Locked = true;  
freeText.NoDelete = true;  
freeText.LockedContents = true;  
freeText.NoMove = true;  
freeText.StrokeThickness = 0;  
freeText.Id = el.Ry + “-author”;  
freeText.Subject = “author”;  
freeText.TextColor = new Annotations.Color(59, 108, 180);  
annotManager.addAnnotation(freeText);  
annotManager.redrawAnnotation(freeText);

Issue is, there are some documents having wrong X Y axis

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/3/3cf3fc072a3c79250ce9ffc4340fe73bd28b0653.png)

In this specific document, PDF express text annotation is getting placed correctly but our custom generated text is getting placed 90 degrees rotated due this coordinate mix-up. Is there anyway to resolve this

---

<div class="post-metadata">

**Author:** ![jkung](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jkung](https://pdfjs.community/u/jkung)\
**Post date:** [April 25, 2023, 12:39am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/3 "2023-04-25T00:39:07Z")

</div>

Hi Lakshan,

Thank you for contacting us regarding pdf express.

I will investigate the issue and update you once we have further progress.

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [April 27, 2023, 3:50am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/4 "2023-04-27T03:50:03Z")

</div>

Hi, Any update on this?

---

<div class="post-metadata">

**Author:** ![jkung](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jkung](https://pdfjs.community/u/jkung)\
**Post date:** [May 1, 2023, 3:59am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/5 "2023-05-01T03:59:42Z")

</div>

Hi Iakshan,

Sorry for the late reply as I was away last week.

We highly suspect that this is caused by the internal document rotation.

To investigate the issue further, could you share the file(s) with me? You can sent the file or share the link to [jkung@apryse.com](mailto:jkung@apryse.com).

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [May 3, 2023, 9:45am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/6 "2023-05-03T09:45:04Z")

</div>

Attached the file below

[Cinnamon Red, LLC\_\_Credit Card Activity Report (2).pdf](https://pdfjs.community/uploads/short-url/jy7j7MxRkehUGZGb86L8K18vp8I.pdf) (58.8 KB)

---

<div class="post-metadata">

**Author:** ![jkung](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jkung](https://pdfjs.community/u/jkung)\
**Post date:** [May 6, 2023, 1:25pm UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/7 "2023-05-06T13:25:52Z")

</div>

Hi Iakshan,

Thank you for providing the information.

I will look into the issue and update you once we have further progress.

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [May 9, 2023, 11:46am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/8 "2023-05-09T11:46:13Z")

</div>

Hi,

Any update on this

---

<div class="post-metadata">

**Author:** ![jkung](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jkung](https://pdfjs.community/u/jkung)\
**Post date:** [May 9, 2023, 3:14pm UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/10 "2023-05-09T15:14:27Z")

</div>

Hi Iakshan,

Sorry for the late reply as I missed sending out the reply.

After looking into the document you provided, the internal document rotation is 90 degrees, that means you will need to apply the same degree to the programmatically added free text annotation.

To further investigate the issue, could you provide the whole code snippet to add the free text annotation in the annotationChanged event? thank you.

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [May 10, 2023, 11:55am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/11 "2023-05-10T11:55:03Z")

</div>

Custom text code:

```
            const freeText = new Annotations.FreeTextAnnotation();
            var timeStamp = serverTime ? serverTime : moment().format("MM-DD-YYYY HH:mm:ss");
            freeText.PageNumber = PageNumber; //el.PageNumber;
            freeText.X = X; //LeftMost;
            freeText.Y = Y + Height; //BottomMost;
            freeText.Width = authorWidth;
            freeText.Height = authorHeight;
            freeText.setContents(userObj.nickname + "\n" + timeStamp);
            freeText.FontSize = "12pt";
            freeText.Locked = true;
            freeText.NoDelete = true;
            freeText.LockedContents = true;
            freeText.NoMove = true;
            freeText.StrokeThickness = 0;
            freeText.Id = el.Ry + "-author";
            freeText.Subject = "author";
            freeText.TextColor = new Annotations.Color(59, 108, 180);
            annotManager.addAnnotation(freeText);
            annotManager.redrawAnnotation(freeText);

```

1. How to identify internally rotated documents?
2. How to get the current rotation value of the document and pass it to freetext?

I tried freeText.Rotation = 90;.  
Text is getting rotated, But there are number of issues.

Main problem is, after we merge pdf with pdf express merge API original text annotations are getting rotated

This is an example just using pdfexpress text tool (without custom texts)

Before merge

 ![5cb95dca263bffb44cdecfea8d6e0defb24a646c_2_1035x552](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/7/7813a7b16e5433fdf51626a70fecadbc39302717.png)

After merge

 ![44adf7edd596d493af3c8480a93d10b758021c8f_2_1035x553](https://canada1.discourse-cdn.com/flex031/uploads/pdfjscommunity/original/2X/1/1b0fadf027e173d26940e758beefedd78b147aa0.png)

---

<div class="post-metadata">

**Author:** ![jkung](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jkung](https://pdfjs.community/u/jkung)\
**Post date:** [May 16, 2023, 5:28am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/12 "2023-05-16T05:28:51Z")

</div>

Hi Iakshan,

Thank you for providing the information.

To get the rotation of the page, you can use `instance.Core.documentViewer.getDocument().getPageRotation(1)` to get the rotation, and it’s 90 degrees.

Could you provide the whole code snippet for merging?

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [May 16, 2023, 10:07am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/13 "2023-05-16T10:07:51Z")

</div>

Back-end code:

exports.mergeAnnotations = async function (req, res) {  
try {  
const utils = new Utils({  
serverKey: serverKey,  
clientKey: clientKey,  
});  
utils.setFile(req.body.file).setXFDF(req.body.xfdf);  
const response = await utils.merge(); // merge XFDF  
const mergedFile = await response.getBlob();  
res.send({ url: response.url, key: response.key, blob: mergedFile });  
} catch (error) {  
res.status(500).send(error);  
}  
};

Front-end code:  
const xfdf = await annotManager.exportAnnotations({ links: false, widgets: false });  
const pdfExpressData = new FormData();  
pdfExpressData.append(“file”, s3File);  
pdfExpressData.append(“xfdf”, xfdf);  
pdfExpressData.append(“license”, licenseKey);

```
            const response = await fetch("/merge-annotations", {
              method: "post",
              body: pdfExpressData,
            }).then((resp) => resp.json());
            const { url, key, mergedBlob } = response;
            // Download the file
            const mergedFileBlob = await fetch(url, {
              headers: {
                Authorization: key,
              },
            }).then((resp) => resp.blob());
            var pdfblob = new Blob([mergedFileBlob], { type: "application/pdf" });

```

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [May 19, 2023, 12:36pm UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/14 "2023-05-19T12:36:20Z")

</div>

Hi,

any update on this?

---

<div class="post-metadata">

**Author:** ![lakshan](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lakshan](https://pdfjs.community/u/lakshan)\
**Post date:** [June 15, 2023, 6:33am UTC](https://pdfjs.community/t/xy-coordinate-issue-for-some-documents/2534/15 "2023-06-15T06:33:37Z")

</div>

Hi,

any update on this?
