The PDF images created by wordpress are stored within the PDF attachment object metadata.
[
{
"id": 121,
"media_type": "file",
"mime_type": "application/pdf",
...
"media_details": {
"sizes": {
"full": {
...
"source_url": "<domain>/wp-content/uploads/document-name-pdf.jpg"
}
}
]
Extracting the image from the PDF
Adding an image block or adding a featured image to a post requires an attachment ID
and not simply a url probably
An attachment ID
can be created by “side loadeding” the url
into the media library to create an attachement using the media_sideload_image
function which can return the newly created attachment ID
Example
$pdf_image_url = $PDF_object -> media_details -> sizes -> full -> source_url;
$attachment_id = media_sideload_image(
$pdf_image_url,
$post_id, // the post to attach the image
'My image title',
$return_type="id"
);
$image = set_post_thumbnail( $post_id, $attachment_id );
Set Post Thumbnail
The function set_post_thumbnail( $post_id, $attachment_id )
can be used to assign an image to a post as the featured image