1. Home
  2. Foxit Quick PDF Library
  3. How do I programmatically create thumbnails for pages in PDFs?

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");
Updated on April 10, 2017

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial