0

In my system, there are multiple PDFs listed in the website. I need to show the preview image of 1st page of all the PDFs. There are two previews which I want to display -

  • One small preview
  • One big preview on mouse hover

What I am doing now?

We are taking help few third party preview generators. Which is used to create JPEG image and using those images in the website for previews.

What I tried differently?

I used EvoPDFtoHTML tool to use HTML instead of images directly but for many files the generated HTML is not appropriate.

Also, These both process is taking a lot of time and making website slow in response.

I would like to know that is there any better way to achieve this?

Image attached below for better understandings -

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Arpit Gupta
  • 1,209
  • 1
  • 22
  • 39
  • You can try google doc viewer, and embed an iframe that points to pdf in google doc viewer – Clint Dec 19 '19 at 05:36
  • Example that I could find: – Clint Dec 19 '19 at 05:46
  • Won't it target the full PDF for preview? I want only first page as the preview. – Arpit Gupta Dec 19 '19 at 05:49
  • yes it would, have you thought of parsing the pdf first to extract page 1 and then use it for preview ? – Clint Dec 19 '19 at 06:00
  • okay.. I will try that out.. (Y) – Arpit Gupta Dec 19 '19 at 06:18
  • Hi @Arpit, please let me know if u solved it, just curious to know if it worked out.. – Clint Jan 15 '20 at 14:45
  • Hi @Clint, We still not came to any solution. Currently we are stuck with loading issues. As it will take a lot of time to load the preview. Which is not acceptable. We also looked on Lazy Loading but that idea also got rejected due to scrolling looks bad. One more thing we thought of CDN hosting but security issue. So currently stuck. – Arpit Gupta Jan 16 '20 at 06:46

1 Answers1

0

An approach that is worth exploring

  • Parse the PDF and extract the 1st page.You may use command line tools like : PDFtk, Ghostscript, or Implement your own class to parse out the first page in C#
  • Then use Google doc viewer and embed an iframe to point to PDF

Example of PDFtk:

pdftk input.pdf cat 1 output page-1-of-input.pdf

Example of GhostScript:

gs -o page-1-of-input.pdf -sDEVICE=pdfwrite -dPDFLastPage=1 input.pdf

References:

Display first page of PDF as Image

You can also look at Fahims answer for the C# snippet that he tried

Clint
  • 6,011
  • 1
  • 21
  • 28