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.
IndexProgramming Questions & HelpOther Libraries › Odd displacement in PDFs
Page Index Toggle Pages: 1
Odd displacement in PDFs (Read 428 times)
Odd displacement in PDFs
Oct 15th, 2007, 9:18am
 
I've been working on my very first sketch in which I bring XML data into processing, dynamically load SVGs and export out PDFs.  It has been a bit of a challenge, but I'm nearly there.  At the moment, I've been trying to use translate and rotate to position and turn my SVG imagery in a void draw().  

When I run the sketch normally, the window displays things properly.  However, the resultant PDF is totally out of whack.  When opening the PDF in Illustrator, I see the background image and all the vectors have been added, but the vectors are in totally the wrong place.  

Doing testing, I discovered that when translate and rotate are removed, the resultant PDF is exactly the same as the display window.  This leads me to guess that the PDF export  doesn't respect the reset on the translate and rotate when the loop happens (as is in the documentation on both).

Does anyone have any suggestions on how to get around this issue?

[edit]

It appears that the issue revolves around the buffer in the PDF lib.  ProSVG clears the buffer every time draw is run, but the PDF lib doesn't, resulting in the multiple layering issue.  

(for reference, my code is below)

Code:

import processing.xml.*;
import processing.candy.*;
import processing.pdf.*;

XMLElement xml;
String[] vector;
float[] xPos, yPos, rotateStore;
color[] colorStore;
int numSites;

SVG SVGStore;

void setup() {
size(800, 600);
xml = new XMLElement(this,"test.xml");
numSites = xml.getChildCount();
beginRecord(PDF, "exported/"+xml.getChild(numSites-5).getContent()+".pdf");
background(xml.getChild(numSites-1).getIntAttribute("red"),xml.getChild(numSites-1).getIntAttribute("green"),xml.getChild(numSites-1).getIntAttribute("blue"));

vector = new String[numSites];
xPos = new float[numSites];
yPos = new float[numSites];
colorStore = new color[numSites];
rotateStore = new float[numSites];

for (int i = 0; i < numSites-5; i++) {
XMLElement kid = xml.getChild(i);

vector[i] = "svg/"+kid.getContent();
xPos[i] = kid.getIntAttribute("xPos");
yPos[i] = kid.getIntAttribute("yPos");
colorStore[i] = color(xml.getChild(i).getIntAttribute("red"),xml.getChild(i).getIntAttribute("green"),xml.getChild(i).getIntAttribute("blue"));
rotateStore[i] = radians(kid.getFloatAttribute("rotate"));

//println("vector: "+vector[i]+" xPos: "+xPos[i]+" yPos: "+yPos[i]+" color: "+colorStore[i]+" rotateVal: "+rotateStore[i]);
}
};

int drawController = 0;

void draw() {
translate(xPos[drawController],yPos[drawController]);
rotate(rotateStore[drawController]);
SVG imageStore = new SVG(this,vector[drawController]);
imageStore.ignoreStyles(true);
fill(colorStore[drawController]);
noStroke();
smooth();
imageStore.draw(0,0);
drawController++;

if (drawController == numSites-5){
noLoop();
endRecord();
exit();
};
};


Page Index Toggle Pages: 1