You must call CGPDFContextClose for the PDF data to be written:
// ...
CGPDFContextEndPage(pdfContext);
// Close the PDF document
CGPDFContextClose(pdfContenxt);
CGContextRelease(pdfContext);
// ...
The documentation notes that closing the context causes data to be written, which might explain why you're getting a blank PDF without closing:
After closing the context, all pending data is written to the context destination, and the PDF file is completed. No additional data can be written to the destination context after the PDF document is closed.