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 & HelpSyntax Questions › Problem exporting PDF
Page Index Toggle Pages: 1
Problem exporting PDF (Read 801 times)
Problem exporting PDF
Feb 11th, 2010, 10:25am
 
hey! i got this code and i wanted to export a pdf but the problem is, when ever i open the PDF in acrobat it says that i the file has an error.

here's my code... am i doing something wrong in my export?

Code:
import processing.pdf.*;



color[] mycolours = {
// color(215,161,44),color(11,17,3),color(32,75,8),color(86,138,20),color(56,108,12),color(247,94,43),color(150,105,17),color(44,45,9),color(236,59,25),color(246,130,49),color(114,59,13),color(97,100,25),color(146,133,23),color(127,160,40),color(173,70,16),color(203,90,27)};
color(190,193,208),color(133,55,21),color(50,79,139),color(28,17,70),color(103,136,181),color(211,137,71)};
String[] shapeNames = { "A.svg" , "B.svg"};
PShape[] shapes;

int num = 1;

void setup(){


//---------------------
size(800,600);
smooth();
background(255);
//_____________________________

shapes = new PShape[shapeNames.length];
for (int s = 0; s < shapes.length; s++)

shapes[s] = loadShape(shapeNames[s]);


//______________________________________

}


void draw(){
beginRecord(PDF, "grid_7_"+ num + ".pdf");
float rot=random(10);
//rotate(rot);
noStroke();



//translate(10,10);




for(int i = 0 ;i < 800; i = i+20){
for(int j = 0 ;j < 600; j= j+20){

PShape shapeToDraw = shapes[int(random(shapes.length))];
scale(random(3));
float trans = random(50,100);

shapeToDraw.disableStyle();


color cor2 = mycolours[int(random(mycolours.length))];
color cor = mycolours[int(random(mycolours.length))];

fill(cor2,trans);
//strokeWeight(random(4));
//stroke(cor);
float rnd = random(4);

shapeMode(CENTER);
float xprop = shapeToDraw.width*rnd;
float yprop = shapeToDraw.height*rnd;
shape(shapeToDraw,i,j, xprop,yprop);
// ellipse(i,j,10,10);

noLoop();

}
}
}

void mousePressed(){
// fill(255,100);
// rect(-1,-1,width+1,height+1);
background(255);
redraw();
}

void keyPressed(){
if(key=='s'){
endRecord();
num++;

}
}
Re: Problem exporting PDF
Reply #1 - Feb 11th, 2010, 12:21pm
 
Hard to tell without the SVG files. Perhaps the problem is there...
Re: Problem exporting PDF
Reply #2 - Feb 11th, 2010, 12:36pm
 
https://www.sendthisfile.com/3BrC3rQSwPrmqdz6R9lgQzHY

i've put them in this link so you can help me, Cheesy thanks for the response btw
Re: Problem exporting PDF
Reply #3 - Feb 11th, 2010, 1:51pm
 
OK, I created a pair of PDF files and I was able to open them in Foxit Reader 2.3 (on XP) and in Adobe Reader 9 (on Win7).

But I experienced some errors... First because I forgot to hit s on the second sketch... So PDF had a size of 0 bytes. Second because the sketch's window was still displayed. Looks like you need to close the sketch to unlock the PDF.
Re: Problem exporting PDF
Reply #4 - Feb 11th, 2010, 1:56pm
 
but i do! yesterday i made 500 pdfs lol and didn't opened them before I closed the sketch.... today I went to print them and there was an error, I thought it was a printer shop's error so i came home and the error existed in my pdf too
Re: Problem exporting PDF
Reply #5 - Feb 11th, 2010, 2:45pm
 
the strange thing is... i've worked with SVGs so many times and exported Them into PDF and i did not had a problem before :s
Re: Problem exporting PDF
Reply #6 - Feb 11th, 2010, 2:54pm
 
I had no problem to open the PDF exported by your program.
Perhaps you can sendthisfile one of such faulty PDF? I doubt I can tell much about it, but I am curious to see if I can open it as well.
Re: Problem exporting PDF
Reply #7 - Feb 11th, 2010, 3:04pm
 
https://www.sendthisfile.com/uZURmT3o3uZvwOXaZcZgHSkP I can open it, but it tells me that there is an error, and that same error made the printer shop not be able to open :s
Re: Problem exporting PDF
Reply #8 - Feb 12th, 2010, 2:14am
 
Foxit Reader opens it without problem.
Adobe Reader 7 says: "Token type not recognized" and doesn't show the document.
Both on WinXP.
Ah, Adobe just asked if I want to upgrade to v.9.3. Let see...
Wow, 26MB! Talk about a lightweight application... I know why I use Foxit on most of the computers I use...
And it expects me to restart after install!

Anyway, Adobe Reader 9.3 doesn't complain about this file.

So, I think the issue is with the version tag of the file. If you open the file with a good text editor (preserving binary data...) or just an hex editor, you can see the first line of the file to be:
%PDF-1.4
Most PDF files I have have 1.3 or lower.
I suppose older versions of Adobe Reader doesn't handle this PDF version.
You have two solutions:
- Ask your printer shop to upgrade! (unlikely...)
- Use a good search/replace utility to change the above tag to 1.3. I guess the files doesn't actually use advanced feature, so the change should be safe.

I suppose we can ask iText (the Java library generating the PDF) to default output to a lower version but it needs investigation...

Page Index Toggle Pages: 1