I have a basic C function, which creates a pdf and then writes it to the disc with HPDF_SaveToFile(pdf, filename)
where pdf
is an instance of HPDF_Doc
.
But now I want to change the function behaviour so instead of writing to disc, it would return pdf as binary, which I will work with elsewhere.
How do I get binary from HPDF_Doc
variable?
Solved, here's how I did it:
HPDF_SaveToStream(pdf);
unsigned int streamSize = HPDF_GetStreamSize(pdf);
unsigned char* buffer = malloc(streamSize * sizeof(buffer));
HPDF_Stream_Read(pdf->stream, buffer, &streamSize);
this way buffer
variable will contain the binary