# Saving SVG: I only want to save the canvas, not lines drawn outside

**URL:** <https://discourse.processing.org/t/saving-svg-i-only-want-to-save-the-canvas-not-lines-drawn-outside/38421>\
**Category:** Coding Questions\
**Created:** [August 19, 2022, 7:55pm UTC](https://discourse.processing.org/t/saving-svg-i-only-want-to-save-the-canvas-not-lines-drawn-outside/38421 "2022-08-19T19:55:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![i-draw-monkeys](https://avatars.discourse-cdn.com/v4/letter/i/c6cbf5/32.png) [@i-draw-monkeys](https://discourse.processing.org/u/i-draw-monkeys)\
**Post date:** [August 19, 2022, 7:55pm UTC](https://discourse.processing.org/t/saving-svg-i-only-want-to-save-the-canvas-not-lines-drawn-outside/38421/1 "2022-08-19T19:55:13Z")

</div>

I am trying to make some SVGs for my pen plotter using math to draw lines. I define the canvas size in setup, but some points that the math designates are outside of this. Here is example code that I simplified where this happens by hardcoding the start point of the line at (-50,0):

```auto
import processing.svg.*;
import java.util.*;
boolean bExportSVG = false;

void setup() {
  size(200, 200);
}

void draw () {
  background(255);

  if (bExportSVG) {
    beginRecord(SVG, "drawing.svg");
  }
  size(200, 200);
  rect(0, 0, width, height);
  line(-50, 0, 50, 100);
  if (bExportSVG)
  {
    endRecord();
    bExportSVG = false;
  }
}

void keyPressed()
{
  if (key == 'e')
  {
    bExportSVG = true;
  }
}

```

When I press “e” the file saves. The code works great. However, when I open the SVG in Inkscape, I get the bounding box rectangle and a line that intersects it and starts at (-50,0) outside of the (200,200) canvas. This is problematic because when I go to plot, I only want to plot what is inside the bounding box or canvas. How can I get the file to save the canvas only?

I would hope it would save only the bounding box and a line from (0,50) to (50,100).

This is a simplified example. In what I am really trying to do there are hundreds of lines landing outside.

(I repeated the size() under beginRecord because I thought that might solve the problem but it didn’t—I started learning Processing a couple weeks ago so very new at this.)

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 21, 2022, 9:02pm UTC](https://discourse.processing.org/t/saving-svg-i-only-want-to-save-the-canvas-not-lines-drawn-outside/38421/2 "2022-08-21T21:02:17Z")

</div>

Duplicate of this thread: [https://discourse.processing.org/t/creating-svg-limited-to-canvas-size/38426/9](https://discourse.processing.org/t/creating-svg-limited-to-canvas-size/38426/9)
