Save multi pages PDF

Hi,

I try to save a multi page PDF with ofBeginSaveScreenAsPDF(“file.pdf”,true) function.
I don’t use the ofApp::draw() function but just a loop for() to iterate all shapes what I want save.

I don’t find solution on the forum or with cairo :expressionless:

for (auto sh : shapes) {

    ofBeginSaveScreenAsPDF("/Users/Desktop/shapes.pdf",true);
    ofDrawRectangle(sh.position, sh.getWidth, sh.getHeight);
    ofEndSaveScreenAsPDF();
}

:v:

What is the error you’re getting? Are you sure about the path? It seems wrong.

Hi,

Sorry for the delay :grimacing:

I do not have an error but it replaces the same page for each record instead of creating a new page :man_shrugging:

It’s just a fake path for this example

Yeah, it sounds like it will behave like that. Your code should look :

 ofBeginSaveScreenAsPDF("/Users/Desktop/shapes.pdf",true);
for (auto sh : shapes) {

    ofDrawRectangle(sh.position, sh.getWidth, sh.getHeight);
}
ofEndSaveScreenAsPDF();

That’s what I did at first, but it does not create a new page. all drawings are on one page :expressionless:

Yeah! The problem, as I see, is that the render happens with the whole draw(). So, perhaps you should have something like:

if (readyToSavePDF) {
    if (!saving) {
          ofBeginSaveScreenAsPDF("/Users/Desktop/shapes.pdf",true);
          saving = true;
          currentSavingShape = 0;
    }

    if (saving) {
        (whatever...) sh = shapes[currentSavingShape];

        ofDrawRectangle(sh.position, sh.getWidth, sh.getHeight);

        if (currentSavingShape == shapes.size()) {
            saving = false;
            readyToSavePDF = false;
            ofEndSaveScreenAsPDF();
        }
        currentSavingShape++;
    }
}

Yes something happen with ofApp::draw() that start a new page. I don’t identify what is it. I looked in ofGraphics.cpp and in ofCairoRenderer.cpp but I don’t find the solution. :face_with_monocle: