We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
PDF export (Read 4588 times)
PDF export
Jun 14th, 2010, 12:14pm
 
I have been trying to export to a pdf file, and while it looks nice opening it in illustrator,  the objects (rects in this case) are not exported in their exact positions. As im trying to generate a pattern that can be tiled seamlessly, this is quite a big issue for me. So heres one screenshot from the display window and one from the .pdf file, obviously they differ quite much...

Images would go here, but im not allowed to use them in my 1st post...

I hope someone can give me a hint what to do about it (im not doing really much other than callin beginRecord(PDF,"filename.pdf"), drawing rects and call endRecord(); ) or at least confirm that there is a known bug in the PDF lib and i should go back writing my own thing.

cheers
tom
Re: PDF export
Reply #1 - Jun 14th, 2010, 12:15pm
 
... ...

So here they are...
Re: PDF export
Reply #2 - Jun 14th, 2010, 12:51pm
 
i havent had any problems like this using the pdf export before. Neither have i heard of them.

Could you post your code? Would like to check it.
Re: PDF export
Reply #3 - Jun 14th, 2010, 3:19pm
 
the whole thing is actually rather big (about 1000 lines) so i try to give you only those parts i believe are important:

Quote:
import processing.pdf.*;
import processing.opengl.*;

//---------------------------------------------------  Variables for saving an I
mage to Disk

String imagename = "Image"; // Image name
String extension = ".png"; // tif, tga,jpg or png

boolean recordpdf;
boolean writesvg = false;

boolean mouseScale;
boolean mouseAngle;
boolean randomAngle;
boolean randomScale;
boolean seemless;
boolean strokeon;
boolean secondon;
int colorindex;

color backColor = color (255);
color frontColor = color (0,32);
color targetColor = color (0,32);
color strokeColor = color (0,32);
PFont font;
PrintWriter svgout;


MultiColors mc;
Imager im;
int currentIndex;
int pattern = 0;
int maxpattern = 4;
Grid g;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - -

void setup () {
  size(1400,700);
  smooth();
  //hint(ENABLE_OPENGL_4X_SMOOTH);
  background (255);

  imagename = imagename+"-####"+extension;
  rectMode(CENTER);
  ellipseMode(CENTER);
  imageMode(CENTER);
  font = loadFont("BankGothic-Light-10.vlw");
  textFont(font);  
  colorindex = -1;

  mc = new MultiColors (10,10,300,10,0,255);
  im = new Imager(1);

  //cs = new ColorSelector (10,10,300,10,0,255);
  //cs2 = new ColorSelector (10,100,300,10,0,255);
  currentIndex = 1;
  pattern = 0;
  g = new Grid (currentIndex);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - -

void draw () {
  if (recordpdf) beginRecord(PDF,"frame-####.pdf");
  background (backColor);
  g.renderGrid();
  mc.updateMC();
  pushColors();
  if (recordpdf) {
    endRecord();
    recordpdf = false;
  }
}



i use a grid class to calculate possible resolutions that let the tiles fit to the screen size and to create the necessary number of tiles from a tile class. (my intention is to have a system of tiles where i can replace the drawing elements with whatever i want to draw in each tile). so all actual drawing takes place in each tile:

see second post....
Re: PDF export
Reply #4 - Jun 14th, 2010, 3:26pm
 
Quote:
  void tileDrawing() {
    switch(myTile) {
      // -----
    case 0:
      //noStroke();v
      rect (0,0,mySize*myScale,mySize*myScale);
      if (writesvg) {
        
        svgout.println ("<rect x=\"0\" y=\"0\" width=\"" + mySize*myScale + "\" height=\"" + mySize*myScale + "\" fill=\"#" + hex(myLerpColor, 6)  + "\" opacity=\"" + myOpacity +"\" transform=\"translate(" + (myX-(mySize*myScale/2)) + "," + (myY-(mySize*myScale/2)) + ") rotate(" + int(degrees(myAngle)) + ", "+ (mySize*myScale/2) + ", "+ (mySize*myScale/2) +")\" />");
      }
      break;
      // ---------
    case 1:
      ellipse (0,0,mySize*myScale,mySize*myScale);
      break;
      // ---------
    case 2:
      line (-mySize*myScale,-mySize*myScale,mySize*myScale,mySize*myScale);
      break;
      // ---------
    case 3:
      imageMode(CENTER);
      image (myImage,0,0,mySize*myScale,mySize*myScale);
      break;
    }
  }
  // - - - - - - - - - -  
  void renderTile () {
    fill (myColor);
    myLerpColor = myColor;
    if (secondon) {
      myLerpColor = lerpColor(myColor,targetColor,lerpValue);
      fill (myLerpColor);
      tint (myLerpColor);
    } else {
    tint (myColor);
    }
    myOpacity = map(alpha(myLerpColor),0,255,0,1);
    if (strokeon) {
      stroke (strokeColor);
    } 
    else {
      noStroke();
    }
    pushMatrix();
    translate (myX,myY);
    rotate(myAngle);
    if (writesvg) {
      //svgout.println ("<g  >");
      //svgout.println ("<g transform=\"rotate(" + int(degrees(myAngle)) + ")\">");
      //<g transform="translate(50,90)">
    }
    tileDrawing();
        if (writesvg) {
      //svgout.println ("</g>");
      //svgout.println ("</g>");
      //<g transform="translate(50,90)">
    }
    popMatrix();
    if (outside) {
      for (int i = 0; i < 8;i++) {
        pushMatrix();
        switch (i) {
          // -------------------------------------- links
        case 0:
          translate(myX-g.myWidth,myY);
          break;
          // -------------------------------------- rechts
        case 1:
          translate(myX+g.myWidth,myY);
          break;
          // -------------------------------------- oben
        case 2:
          translate(myX,myY-g.myHeight);
          break;
          // -------------------------------------- unten
        case 3:
          translate(myX,myY+g.myHeight);
          break;
          // -------------------------------------- links oben
        case 4:
          translate(myX-g.myWidth,myY-g.myHeight);
          break;
          // -------------------------------------- rechts oben
        case 5:
          translate(myX+g.myWidth,myY-g.myHeight);
          break;
          // -------------------------------------- links unten
        case 6:
          translate(myX-g.myWidth,myY+g.myHeight);
          break;
          // -------------------------------------- rechts unten
        case 7:
          translate(myX+g.myWidth,myY+g.myHeight);
          break;
        }
        rotate(myAngle);
        tileDrawing();
        popMatrix();
      }
    }
  }
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
  void outofbounds () {
    if (myX+(mySize*myScale)/2 > g.myWidth || myX-(mySize*myScale)/2 < 0 || myY+(mySize*myScale)/2 > g.myHeight || myY-(mySize*myScale)/2 < 0) {
      outside = true;
      //println ("draussen");
    }

  }

Re: PDF export
Reply #5 - Jun 14th, 2010, 3:30pm
 
right now theres some lines in the code where i try to write to an svg file, but as i use a dedicated boolean (which is on false) i do not think thats part of the problem anyway...

im sorry to post that many lines of code, maybe you can make sense of it. or, if you want i will try to reduce it to the absolute minimum and post it, but that will take me a bit of time... Smiley

tx, tom

Re: PDF export
Reply #6 - Jun 14th, 2010, 10:19pm
 
hmm ok, that is more than i was expecting. i was actually hoping for a running version to check it, as it is much easier to find the problem then reading through your code and try to understand what happens. Especially your code looks more complex and there are still some classes missing, the problem could be everywhere. did you try to reproduce the problem with a simpler version of your code? just try to narrow it down, remove everything that is not really needed until you get to the part where the problem happens...
I still dont think that it is a problem of the pdf export itself.
If somebody knows better, let us know.
Re: PDF export
Reply #7 - Jun 15th, 2010, 3:26pm
 
yeah, ok. im aware its a bit long. ill take up your advice and try to reduce it to a state where the problem still occurs with as few lines i can manage.

cheers, tom
Re: PDF export
Reply #8 - Jun 16th, 2010, 7:48am
 
so heres a patch that does basically the same, drawing some rects on the display and writing it to a .pdf file. the display and the pdf still differ and i realize it is only when i use rectMode(CENTER) that the pdf doesnt equal the image on the display.
despite having found the problem i would still appreciate any suggestion how to be able to draw in center-mode AND get an accurate pdf being written.

tom

Quote:
import processing.pdf.*;

float x;
float y;
float rSize;
float a;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - -

void setup () {
  size (640,480);
  background(255);
  noStroke();
  rectMode(CENTER);
  beginRecord(PDF,"frame-####.pdf");
  for (int i = 0; i<100;i++) {
    fill (random (200,255),0,0,random (15,128));
    x = random(0,width);
    y = random(0,height);
    a = random(-PI,PI);
    rSize = random(15,50);
    pushMatrix();
    translate(x,y);
    rotate(a);
    rect(0,0,rSize,rSize);
    popMatrix();
  }
  endRecord();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - - - - - - -

void draw () {

}

Re: PDF export
Reply #9 - Jun 16th, 2010, 8:26am
 
call rectMode after beginRecord, thats it...
Re: PDF export
Reply #10 - Jun 16th, 2010, 10:35am
 
lol, thank you so much, another proof there are really easy answers to questions that i would never think of Wink

... just an addendum: i managed to create a 4 by 4 meter canvas with 10 k objects as a pdf file (240k size). that really rocks, so thank you for creating that cool pdf export lib !
Re: PDF export
Reply #11 - Jun 16th, 2010, 12:10pm
 
no problem Smiley thats why it is always a good idea to break it down. the problem is much easier to spot then
Page Index Toggle Pages: 1