Hello. Pdfium for
FPDFImageObj_LoadJpegFile use FPDF_FILEACCESS struct. Which have at m_GetBlock field the pointer to read function.
So if you want read jpg image from file, you need create read function and fill
FPDF_FILEACCESS struct.
Something like that:
int ReadBlockFromFile(void* param, unsigned long position, unsigned char* pBuf, unsigned long size)
{
FILE* fileHandle= (FILE*)param;
fseek(imageFile,
position
, SEEK_SET);
fread(
pBuf ,
size
,1,
fileHandle
)
return size;
}
FILE* jpgFile= fopen("img.jpg", "rb");
if (
jpgFile
!= nullptr)
{
fseek(
jpgFile
, 0, SEEK_END);
long fileSize = ftell(
jpgFile
);
fseek(
jpgFile
, 0, SEEK_SET);
FPDF_FILEACCESS fileReadObj;
fileReadObj
.m_FileLen = fileSize;
fileReadObj
.m_Param =
jpgFile
;
fileReadObj
.m_GetBlock =
ReadBlockFromFile
;
//create image
FPDF_PAGEOBJECT page_obj_image = FPDFPageObj_NewImageObj(pdf_doc);
FPDFImageObj_LoadJpegFile(nullptr, 0, page_obj_image, &
fileReadObj
);
FPDFPage_InsertObject(pdf_page, page_obj_image);
fclose(
jpgFile
);
}
For use png you need convert it to BMP , then create by FPDFBitmap_CreateEx bitmap and pass at last parameter the bmp pixels memory.