# PDF / SVG libraries - rectMode(CENTER) not working

**URL:** <https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878>\
**Category:** Libraries\
**Created:** [February 17, 2021, 11:44am UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878 "2021-02-17T11:44:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 17, 2021, 11:44am UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878/1 "2021-02-17T11:44:40Z")

</div>

Hi there

So I’ve got a project, I go to export the files, all works as expected except for the rectangles which are now in the wrong positions. Same error with PDF and SVG libraries.

Is this a known issue with rectMode(CENTER)?

Does anyone have a workaround for this aside from me repositioning every rectangular element?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 17, 2021, 1:39pm UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878/2 "2021-02-17T13:39:42Z")

</div>

I ended up translating all my rectangle positions. Got the output I need now. Weird I couldn’t find any mention of this rectMode() thing online. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [February 17, 2021, 2:27pm UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878/3 "2021-02-17T14:27:02Z")

</div>

Hi,

Look at the following examples, they work perfectly fine 😉 :

## → Export to PDF

```auto
import processing.pdf.*;

void setup() {
  size(400, 400, PDF, "output.pdf");
}

void draw() {
  rectMode(CENTER);
  rect(width / 2, height / 2, 100, 100);
  
  exit();
}

```

![Capture d’écran de 2021-02-17 15-23-03](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/36c78fcefb92077cf214b5401863107fec6780a5.png)

* * *

## → Export to SVG

```auto
import processing.svg.*;

void setup() {
  size(400, 400, SVG, "output.svg");
}

void draw() {
  rectMode(CENTER);
  rect(width / 2, height / 2, 100, 100);

  exit();
}

```

![Capture d’écran de 2021-02-17 15-24-06](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f875110155e7a822a169b8c37cbb8d26a8b1466e.png)

---

<div class="post-metadata">

**Author:** ![xiiixiii](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xiiixiii](https://discourse.processing.org/u/xiiixiii)\
**Post date:** [February 17, 2021, 2:42pm UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878/4 "2021-02-17T14:42:29Z")

</div>

Thankyou for those. Tthey work perfectly, mine is all messed up 😆

My rectangles are also translated / rotated inside push/pop matrixes though, maybe that’s related?

Either way I found a route out of the madness 🙂

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [February 17, 2021, 2:47pm UTC](https://discourse.processing.org/t/pdf-svg-libraries-rectmode-center-not-working/27878/5 "2021-02-17T14:47:23Z")

</div>

You are welcome! 😉

> [@xiiixiii](#):
>
> My rectangles are also translated / rotated inside push/pop matrixes though, maybe that’s related?

Yes that’s probably the case, to rotate a rectangle on its center for example be careful to push and pop the matrix before drawing any other shapes that you don’t want to transform and use `rectMode(CENTER)` to center it.
