Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →For a PDF, use Mozilla PDF.js to render page 1 into a canvas in the browser, or use PHP Imagick to rasterize page index [0] on the server. These approaches do not establish support for DOCX, XLSX, or other office formats; confirm the actual upload formats before choosing a renderer. Treat every upload as untrusted input and validate it before parsing.
Choose where the PDF preview should be rendered
| Consideration | Browser-side PDF.js | Server-side PHP Imagick |
|---|---|---|
| Where it runs | The user’s browser, with the page drawn to a canvas. | Your PHP server, which reads the PDF page and writes an image. |
| First-page reference | Request page number 1 with PDF.js. |
Read page index [0] with Imagick. |
| Upload transfer | A local file can be previewed in the browser without sending it to your server when the use case allows. | The PDF is uploaded to the server and must be validated before conversion. |
| Deployment needs | A compatible PDF.js distribution and worker, served over HTTP. | PHP Imagick and a local environment configured to read PDFs; verify the PDF delegate and configuration for your deployment. |
| Resource control | Render only the page needed for the preview; partial fetching of remote PDFs depends on Range Request support. | Set output resolution and constrain processing based on your workload and security policy. |
Use PDF.js when the user needs an immediate local preview and you do not need a server-generated image. Use Imagick when your application needs to create and store an image on the server. If the input formats include more than PDFs, add a renderer that explicitly supports those formats rather than assuming either example handles them.
Preview a selected PDF in the browser with PDF.js
PDF.js separates its parsing core, display API, and viewer UI. For a simple preview, the display API is enough: load the selected file, await the loading task, request page 1, choose a viewport size, and render the page to a canvas.
Install and serve a compatible PDF.js build
The PDF.js getting-started documentation lists a prebuilt stable distribution and its corresponding worker; pin compatible package and worker versions in your application. Use the current version shown in that documentation rather than copying a version number from an older tutorial. The worker is not enabled when the application is opened through file://, so run the project through an HTTP development server. Check the project’s current browser guidance before deploying.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Documentation: PDF.js: Getting Started and PDF.js examples.
HTML for the file input and preview canvas
<label for="pdf-file">Choose a PDF</label>
<input id="pdf-file" type="file" accept="application/pdf,.pdf">
<p id="preview-status" role="status"></p>
<canvas id="pdf-preview"></canvas>
The accept attribute helps guide file selection, but it is not file validation. A user or script can still supply a different file; handle loading failures and apply your application’s format checks.
JavaScript rendering code
This example assumes your build provides the PDF.js display library and worker as importable modules. Set the worker source to the matching worker file from the same pinned PDF.js build.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import * as pdfjsLib from "pdfjs-dist";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.mjs?url";
pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;
const input = document.getElementById("pdf-file");
const canvas = document.getElementById("pdf-preview");
const status = document.getElementById("preview-status");
const context = canvas.getContext("2d");
input.addEventListener("change", async () => {
const file = input.files?.[0];
if (!file) return;
status.textContent = "Loading PDF…";
canvas.width = 0;
canvas.height = 0;
try {
const bytes = new Uint8Array(await file.arrayBuffer());
const loadingTask = pdfjsLib.getDocument({ data: bytes });
const pdf = await loadingTask.promise;
const page = await pdf.getPage(1);
// Scale the page to fit a 720 CSS-pixel preview width.
const cssWidth = 720;
const baseViewport = page.getViewport({ scale: 1 });
const scale = Math.min(1, cssWidth / baseViewport.width);
const viewport = page.getViewport({ scale });
const outputScale = window.devicePixelRatio || 1;
canvas.width = Math.floor(viewport.width * outputScale);
canvas.height = Math.floor(viewport.height * outputScale);
canvas.style.width = `${Math.floor(viewport.width)}px`;
canvas.style.height = `${Math.floor(viewport.height)}px`;
await page.render({
canvasContext: context,
viewport,
transform: outputScale !== 1
? [outputScale, 0, 0, outputScale, 0, 0]
: null
}).promise;
status.textContent = "First page ready.";
} catch (error) {
console.error(error);
status.textContent = "Could not preview this PDF. Check the file and try again.";
}
});
For a production interface, release references to the previous document and page when replacing a selection, and provide a visible error state rather than leaving a blank canvas. Exact package import paths can differ between bundlers; use the worker entry point documented for the PDF.js build you have pinned.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchViewport size and sharpness
The viewport controls the page’s CSS dimensions. This example caps it at 720 CSS pixels wide and at scale 1, then uses the device pixel ratio for the canvas backing resolution on high-density displays. A larger backing canvas can look sharper, but consumes more memory. Pick dimensions appropriate to the preview area and device instead of rendering at print resolution when the user only needs a thumbnail.
Generate the first-page image on the server with PHP Imagick
Imagick can read a selected PDF page using ImageMagick’s bracket syntax. Page indices in the documented example are zero-based, so [0] selects the first page. Set the resolution before reading: raster dimensions are determined during PDF rendering.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Validate and stage the upload
Before invoking a PDF renderer, check the PHP upload error, apply your application’s file-size limit, inspect the temporary file’s MIME type instead of trusting the client-supplied MIME field, and create a safe server-generated filename. Use is_uploaded_file() when you need to confirm that the temporary path came through an HTTP POST upload.
<?php
if (!isset($_FILES['document'])) {
http_response_code(400);
exit('No file received.');
}
$upload = $_FILES['document'];
if ($upload['error'] !== UPLOAD_ERR_OK) {
http_response_code(400);
exit('Upload failed.');
}
if (!is_uploaded_file($upload['tmp_name'])) {
http_response_code(400);
exit('Invalid upload source.');
}
// Set this limit to the policy for your own application.
$maxBytes = 10 * 1024 * 1024;
if ($upload['size'] > $maxBytes) {
http_response_code(413);
exit('File is too large.');
}
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($upload['tmp_name']);
if ($mime !== 'application/pdf') {
http_response_code(415);
exit('Only PDF files are accepted.');
}
$workDir = __DIR__ . '/private-previews';
if (!is_dir($workDir) && !mkdir($workDir, 0700, true)) {
http_response_code(500);
exit('Could not create preview storage.');
}
$storedPdf = $workDir . '/' . bin2hex(random_bytes(16)) . '.pdf';
if (!move_uploaded_file($upload['tmp_name'], $storedPdf)) {
http_response_code(500);
exit('Could not store upload.');
}
try {
$image = new Imagick();
$image->setResolution(150, 150);
$image->readImage($storedPdf . '[0]');
$image->setImageFormat('jpeg');
$image->setImageBackgroundColor('white');
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$previewPath = $workDir . '/' . bin2hex(random_bytes(16)) . '.jpg';
$image->writeImage($previewPath);
$image->clear();
$image->destroy();
// Return an application-controlled preview URL or stream the file here.
echo 'Preview generated.';
} catch (Throwable $e) {
http_response_code(422);
echo 'Could not render the first PDF page.';
} finally {
// Decide retention and cleanup according to your application's policy.
if (isset($image) && $image instanceof Imagick) {
$image->clear();
$image->destroy();
}
}
?>
The sample’s 10 MiB upload cap and 150 dpi setting are illustrative application choices, not universal safety or quality limits. The PHP Imagick manual demonstrates reading myfile.pdf[0] and writing an image, and notes that resolution should be set before reading for better output quality: Imagick::readImage. JPEG has no transparency, so the example flattens the image against white; select another output format or background policy if that better suits your interface.
Server-side limits are deployment-specific
Neither the cited PHP documentation nor the Imagick example supplies a universal safe maximum for upload bytes, rendered pixels, execution time, process count, or concurrency. Set limits based on expected PDFs, server capacity, renderer behavior, and the consequences of resource exhaustion. Keep originals and generated previews in storage with access controls appropriate to the documents; do not make user uploads public by default.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Keep preview work bounded
Render only the page the interface needs. PDF.js recommends rendering visible pages rather than eagerly creating canvases for every page, which can increase memory use. A first-page preview should not trigger a render of all pages. For remote PDFs, partial fetching may reduce initial transfer, but it depends on HTTP Range Requests support in both the browser and server; do not assume it is available in every deployment.
On the server, resolution directly affects the raster output dimensions and processing demand. Avoid accepting an unbounded workload: establish application-specific file, pixel, time, and concurrency policies, and test them against representative files in the environment where conversion will run.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Common problems and fixes
- The browser reports a worker or fake-worker error: make sure the worker file comes from the same pinned PDF.js build as the display API, and use the worker import method supported by your bundler.
- The page opened from disk will not render: serve the application over HTTP during development; PDF.js does not enable its worker when used with
file://. - The canvas stays blank: await both the document loading task and the page render promise, check the browser console, and confirm the selected file is actually a readable PDF.
- The PHP conversion says no delegate or cannot read the PDF: verify that the server’s ImageMagick/Imagick installation is configured to read PDFs. The cited PHP manual example does not enumerate platform-specific delegate setup.
- The JPEG preview has an unexpected background: flatten transparency against an explicit background before writing JPEG, or choose an output format that supports transparency.
- Large files or high-resolution renders fail or exhaust resources: reduce output resolution or constrain accepted work, then set deployment-specific byte, pixel, time, and concurrency limits. There is no universal limit established by the PHP example.
- A DOCX or spreadsheet is rejected: these examples are PDF workflows. Add a format-specific rendering/conversion path or narrow the accepted file types.
When to use a PDF viewer SDK instead
If the requirement grows beyond a thumbnail into a fuller in-browser PDF experience, a viewer SDK is another option. Apryse documents loading a File from an input into PDF.js Express Viewer, and distinguishes a free, limited viewer from its commercial PDF.js Express Plus SDK. Check its current documentation for the feature and licensing terms you need: PDF.js Express documentation.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Or skip the browser setup: ScreenshotNeo
If what you need is a screenshot of a web page rather than a preview of a user’s uploaded PDF, ScreenshotNeo is a website screenshot API and MCP server. It is not a substitute PDF-upload renderer. A single GET request captures the supplied URL as an image or PDF; see the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. Its MCP server offers screenshot tools for AI agents, and the Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for the free plan.
Frequently Asked Questions
Does this render DOCX or XLSX files too?
No. The described PDF.js and Imagick workflows are for PDF input; office formats need their own supported conversion path.
Which approach keeps a local PDF in the browser?
PDF.js can load the selected browser File and render its first page without uploading it, if the application has no server-side need for the original.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

