Save screen as pdf without the background

Hey guys,

How Do I save the screen(or an fbo) as pdf without saving the background?
Already trie to set ofSetBackgroundAuto(false); but no luck!

Would appreciate any help here.
Thanks in avance

Hey @Joao -

As the OF ‘SaveScreenToPDF’ functions are just creating the PDF from what’s currently being rendered, it seems to me that you will always have a background color as part of the image.

Setting the background to white is easy:

ofSetBackgroundColor(255);

if you need to save out what you are rendering to a PNG with an alpha channel, there are certainly ways to do it. I’m happy to post a code example if you need.

Cheers!

Then again - a way to write a custom PDF exporter is outlined here: Saving screen as pdf without background

but you probably already saw that :wink:

Thanks for your reply @nickhubben, I ended up to make it works with ofCairoRenderer, some of the code in that post was oudated so just for the forum record will post my solution here:

    ofCairoRenderer  pdf;
    ofRectangle viewport;

    viewport.set(0, 0,1000,2000); // pdf dimensions
    ofViewport(viewport);

    pdf.setup("exports/pdf/frame_"+ofToString(frameNum)+".pdf", ofCairoRenderer::PDF);       
    pdf.viewport(viewport);
    pdf.setBlendMode(OF_BLENDMODE_ALPHA);
    pdf.setBackgroundColor(ofColor(0,0,0,0));
    pdf.setFillMode(OF_FILLED);

    pdf.pushMatrix();
    pdf.translate(500,1000);
    pdf.rotate(45);
    
    pdf.scale(1,1); 
    pdf.translate(100,300);
    
    pdf.setColor(255,0,0);
    pdf.drawRect(0, 0, 0, 200, 600);
    
    pdf.popMatrix();

    pdf.close();
    ofViewport(ofRectangle(0,0,ofGetWidth(),ofGetHeight()));

Hope it will be helpful for someone in the future :slight_smile:

1 Like

Great. Thanks for this. Would be great to be able to do this in SaveScreenToPDF too.

1 Like