Foxit Quick PDF Library

How do I programmatically create thumbnails for pages in PDFs?

Creating thumbnails for PDFs using Foxit Quick PDF Library is simple. Simply use the functions listed in the below order:

  • RenderPageToString
  • AddImageFromString
  • SetPageThumbnail

Here is some C# sample code demonstrating how this works:

QP.LoadFromFile("original.pdf");
byte[] ImageContent = QP.RenderPageToString(96, 1, 0);
int ImageID = QP.AddImageFromString(ImageContent, 1);
QP.SelectImage(ImageID);
QP.SelectPage(1);
QP.SetPageThumbnail();
QP.SaveToFile("original_with_thumbnail.pdf");

In this sample I’ve created the thumbnail from the first page in the document and I’ve set the image of the first page as the thumbnail for the first page, but you could set it as the thumbnail for the second, third, fourth, etc, page.

You could also use a different image, not necessarily one from the same document. This example also works with the image off the disk, instead of in memory. Something like:

int DocID1 = QP.LoadFromFile("thumbnail_source.pdf");
QP.RenderPageToFile(96, 1, 0, "thumbnail.bmp");
QP.RemoveDocument(DocID1);
int DocID2 = QP.NewDocument();
QP.SelectPage(1);
QP.SetOrigin(1);
QP.DrawText(100, 100, "Set page thumbnail test");
int ImageID = QP.AddImageFromFile("thumbnail.bmp", 1);
QP.SelectImage(ImageID);
int r = QP.SetPageThumbnail();
QP.SaveToFile("new_page_with_thumbnail.pdf");

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: