# Saving Handy outputs as vectors

**URL:** <https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380>\
**Category:** Libraries\
**Created:** [March 4, 2020, 11:29am UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380 "2020-03-04T11:29:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![epiphany](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/epiphany/32/8286_2.png) [@epiphany](https://discourse.processing.org/u/epiphany)\
**Post date:** [March 4, 2020, 11:29am UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380/1 "2020-03-04T11:29:38Z")

</div>

I normally use PDF export method to save my outputs as vector files. `beginRecord` and `endRecord` always are enough to do this. However I am unable to save Handy Library ([https://github.com/gicentre/handy](https://github.com/gicentre/handy)) outputs as PDFs. In the same code I have some standard lines and rectangles and also some Handy lines. I can see the normal lines & rectangles in the PDF but not the Handy lines.

Do you have any experience or recommendation about this issue, basically any vector output format will work for me?

Thanks very much in advance.

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [March 4, 2020, 12:14pm UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380/2 "2020-03-04T12:14:55Z")

</div>

Are you sure you are enclosing handy drawing within `beginRecord` and `endRecord`? Can you post your code too?

---

<div class="post-metadata">

**Author:** ![epiphany](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/epiphany/32/8286_2.png) [@epiphany](https://discourse.processing.org/u/epiphany)\
**Post date:** [March 4, 2020, 1:55pm UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380/3 "2020-03-04T13:55:05Z")

</div>

It seems that yes, all **Handy** codes are between `beginRecord` and `endRecord`, please see my messy code below:

```auto
import org.gicentre.handy.*;
HandyRenderer h1, h2, h3, h4;
import processing.pdf.*;
import processing.dxf.*;
import processing.svg.*;

void setup()
{
  size(640, 640);
  noLoop();

  beginRecord(PDF, "test.pdf"); 
  h1 = HandyPresets.createPencil(this); 
  fill(0, 204);
  noStroke();
  
  h1.setOverrideStrokeColour(true);
  h1.setStrokeColour(0);
  h1.setRoughness(1);
  //h1.setFillGap(0.5);
  //h1.setFillWeight(5);

  
  float myStep = 4;
  int numberOfBox = 4;
  int miniBoxSize = 75;
  float edgeOffset = 80;
  float boxGaps = ((width - edgeOffset*2) - (miniBoxSize * numberOfBox) ) / (numberOfBox - 1);

  for (float ll=0; ll<=width; ll=ll+myStep) {
    //stroke(255, 0, 0);
    strokeWeight(2);
    line(ll, 0, ll, height);
    stroke(1);
    //noStroke();
  }

  pushMatrix();   

  for (int j=0; j<numberOfBox; j++) {
    pushMatrix();  
    translate (0, edgeOffset + (boxGaps+miniBoxSize)*j);  

    for (int i=0; i<numberOfBox; i++) {
      pushMatrix();  
      translate (edgeOffset + (boxGaps+miniBoxSize)*i, 0);
 if (random(16) < 1) {stroke(255,0,0);} else {stroke(0);}
      rotate(random(-.1, .1));
      for (float rr=0; rr<miniBoxSize; rr=rr+myStep) {

       
        h1.line(0, rr + random(-.99,.99), miniBoxSize, rr+ random(-.1,.1));

      }
      popMatrix();
    }
    popMatrix();
  }
  popMatrix();

endRecord();
  save("normal.png");

}

```

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [March 4, 2020, 2:43pm UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380/4 "2020-03-04T14:43:15Z")

</div>

`beginRecord()` works by intercepting method calls to the PApplet, pointing them to a `recorder` `PGraphics` object internally (see an example from the source code below). I’m guessing the calls to the _Handy_ instance aren’t being captured and pointed to **that** `PGraphics` object because _Handy_ draws to its own `PGraphics` object, and not the PApplet.

```auto
 public void ellipse(float a, float b, float c, float d) {
    if (recorder != null) recorder.ellipse(a, b, c, d);
    g.ellipse(a, b, c, d);
  }

```

So try this instead (here we point handy to draw into the PDF `PGraphics`):

> PGraphics pdf = beginRecord(PDF, “test.pdf”);  
> h1 = HandyPresets.createPencil(this);  
> h1.setGraphics(pdf);

_(note that you might not see what Handy has drawn in the sketch now)_

---

<div class="post-metadata">

**Author:** ![epiphany](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/epiphany/32/8286_2.png) [@epiphany](https://discourse.processing.org/u/epiphany)\
**Post date:** [March 4, 2020, 3:04pm UTC](https://discourse.processing.org/t/saving-handy-outputs-as-vectors/18380/5 "2020-03-04T15:04:19Z")

</div>

Wow! It worked like a charm, thanks very much!

I guess I can redraw the same Handy objects with another instance if I need to see them on screen.
