Thank you for your reply. This problem only appears on specific pdf documents, and I have solved it because there is an anomaly in the data of pdf documents.
But now there is a new problem that the image data in the pdf document I extracted is abnormal. Similarly, this problem only appears in some specific pdf documents. The following is part of my code and one of the pdf documents.
Looking forward to your reply.
int nPageCount = FPDF_GetPageCount(pDocument);
int nImageCount = 0;
for (int i = 0; i < nPageCount; i++)
{
void* page = FPDF_LoadPage(pDocument, i);
int nPageObjectCount = FPDFPage_CountObjects(page);
for (int j = 0; j < nPageObjectCount; j++)
{
void* pageObject = FPDFPage_GetObject(page, j);
int nType = FPDFPageObj_GetType(pageObject);
if (nType == 3)
{
nImageCount++;
DWORD buflen = FPDFImageObj_GetImageDataDecoded(pageObject, NULL, 0);
byte* buffer = new byte[buflen];
FPDFImageObj_GetImageDataDecoded(pageObject, buffer, buflen);
CStringW strFilePath(strDirPath + L'\\');
strFilePath.AppendFormat(L"Image%d.jpg", nImageCount);
WriteBufToFile(strFilePath, buffer, buflen);
delete[] buffer;
buffer = NULL;
}
}
}WriteBufToFile implements only one function to save content of a specified length to a specified file