Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To render an Angular component as an image in the browser, select a DOM element inside its template and pass it to html2canvas after Angular has rendered the view. The returned canvas can be shown, converted to a PNG, or uploaded. This is a DOM-and-CSS reconstruction—not a native screenshot—so unsupported styles, cross-origin assets, server-side rendering, and very large components require special handling.

Render a component after Angular finishes drawing it

Install html2canvas in your Angular project, then mark the element you want to export with a template reference. The example uses Angular’s signal-based viewChild query and afterNextRender, which provides a browser render callback. Angular cautions that DOM completeness is not guaranteed at arbitrary lifecycle-hook times; its render callbacks run after Angular has rendered the application, but do not run during server-side rendering or build-time prerendering (Angular component lifecycle).

npm install html2canvas

Create a standalone component such as this:

import { Component, ElementRef, afterNextRender, viewChild } from '@angular/core';
import html2canvas from 'html2canvas';

@Component({
  standalone: true,
  selector: 'app-card',
  template: `
    <section #captureRoot class="card">
      <h2>{{ title }}</h2>
      <p>{{ description }}</p>
    </section>
  `,
  styles: [`
    .card { padding: 24px; background: white; border-radius: 12px; }
  `]
})
export class CardComponent {
  title = 'A shareable card';
  description = 'This component can be exported as an image.';

  private readonly captureRoot = viewChild.required<ElementRef<HTMLElement>>('captureRoot');

  constructor() {
    afterNextRender(() => {
      const element = this.captureRoot().nativeElement;
      html2canvas(element, {
        windowWidth: element.scrollWidth,
        windowHeight: element.scrollHeight
      }).then(canvas => {
        const pngDataUrl = canvas.toDataURL('image/png');
        // Display, save, or upload pngDataUrl as needed.
      }).catch(error => {
        console.error('Could not render card:', error);
      });
    });
  }
}

The required query returns the referenced element through an ElementRef; its nativeElement is the DOM node that html2canvas accepts. The library’s basic API is html2canvas(element), returning a promise for a canvas (html2canvas: Getting Started).

Trigger capture from a button

If capture should happen only when a user asks for it, keep the query but call html2canvas in the click handler. For a state change immediately before capture, let Angular render that update first by scheduling the capture in a subsequent render callback.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Wacom Intuos Small, Wired Graphic Drawing Tablet with Pen + Software
  • Wacom Intuos Small Graphics Drawing Tablet: Enjoy industry leading tablet performance in superior control and precision with Wacom's EMR, battery free technology that feels like pen on paper
  • Works With All Software: Wacom Intuos tablet can be used in any software program to explore new facets of digital creativity; draw, paint, edit photos/videos, create designs, and mark up documents
  • What the Professionals Use: Wacom's industry leading pen technology and pen to paper feeling makes it the preferred drawing tablet of professional graphic designers
  • Software and Training Included: Only Wacom gives you software with every purchase. Register your Intuos tablet and gain access to some of the best creative software and Wacom's online training
  • Wacom is the Global Leader in Drawing Tablet and Displays: For over 40 years in pen display and tablet market, you can trust that Wacom to help you bring your vision, ideas and creativity to life
import { Component, ElementRef, afterNextRender, viewChild } from '@angular/core';
import html2canvas from 'html2canvas';

@Component({
  standalone: true,
  selector: 'app-export-card',
  template: `
    <section #captureRoot>{{ message }}</section>
    <button type="button" (click)="export()">Export PNG</button>
  `
})
export class ExportCardComponent {
  message = 'Ready to export';
  private readonly captureRoot = viewChild.required<ElementRef<HTMLElement>>('captureRoot');

  export(): void {
    const element = this.captureRoot().nativeElement;
    html2canvas(element, {
      windowWidth: element.scrollWidth,
      windowHeight: element.scrollHeight
    }).then(canvas => {
      const link = document.createElement('a');
      link.download = 'card.png';
      link.href = canvas.toDataURL('image/png');
      link.click();
    }).catch(console.error);
  }

  updateAndExport(): void {
    this.message = 'Updated content';
    afterNextRender(() => this.export());
  }
}

In ordinary click handling, Angular has already rendered the current view before the user can click. If the handler itself changes state and immediately captures, the scheduled callback avoids racing the pending view update. For applications using an older Angular version without signal-based view queries, use that version’s supported @ViewChild query pattern, while still waiting for the browser-rendered element to be ready.

Understand what the resulting canvas represents

html2canvas walks the DOM and reconstructs an image from styles and content it understands. It does not capture the browser’s actual pixels, so the result may differ from what the user sees when a CSS feature is unsupported or only partially supported. The project describes the output as a reconstruction rather than an actual screenshot (html2canvas: Documentation).

It is a reasonable fit for cards, invoices, reports, and straightforward UI snapshots. For highly complex effects, browser-native surfaces, or exact visual fidelity, a screenshot taken from a real browser is a better match to the goal. The library is client-side and intended for modern evergreen browsers, not a Node.js or SSR renderer (html2canvas: Getting Started).

Choose the element and output format

Capture a section, not automatically the whole component

The argument should be the smallest element containing all the content you want. A template reference on a wrapper gives precise control and avoids capturing export buttons or unrelated application chrome. If you need the complete component, put the reference on its outer content wrapper; if you need only a chart or card within it, reference that child instead.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Save or display the canvas

canvas.toDataURL('image/png') gives a PNG data URL that can be assigned to an image’s src or posted to an endpoint. For large images or uploads, canvas.toBlob() avoids building a potentially large base64 string:

Rank #2
Sale
UGEE M708 Drawing Tablet, 10x6 inch Large Space for Digital Drawing
  • Large Active Drawing Space: UGEE M708 V3 graphic drawing tablet features 10 x 6 inch large active drawing space with papery texture surface, provides enormous and smooth drawing for your digital artwork creation, offers no-lag sketch and painting experience
  • 16384 Passive Stylus Technology: A more affordable passive stylus technology offers 16384 levels of pressure sensitivity allows you to draw accurate lines of any weight and opacity according to the pressure you apply to the pen, sharper line with light pressure and thick line with hard pressure for artistry design or unique brush effect for photo retouching
  • Compatible with Multiple System and Softwares: Powerful compatibility, tablet for drawing computer, perform well with Windows 11/10/8/7, Mac OS X 10.10 or later, Android 10.0 or later, mac OS 10.12 or later, Chrome OS 88 or later and Linux; Driver program works with creative software such as Photoshop, Illustrator, Macromedia Flash, Comic Studio, SAI, Infinite Stratos, 3D MAX, Autodesk MAYA, Pixologic ZBrush and more
  • Ergonomically Designed Shortcuts: 8 customizable express keys on the side for short cuts like eraser, zoom in and out, scrolling and undo, provide a lot more for convenience and helps to improve the productivity and efficiency when creating with the drawing tablet
  • Easy Connectivity for Beginners: The UGEE M708 V3 offers USB to USB-C connectivity, plus adapters for USB C, ensuring easy connection to various devices and allowing beginner artists to set up quickly and focus on their creativity without compatibility concerns; Whether using a laptop, desktop, chromebook, or tablet, the UGEE M708 V3 provides a seamless experience for those just starting their digital art journey
canvas.toBlob(blob => {
  if (!blob) {
    throw new Error('Canvas could not be encoded');
  }
  const file = new File([blob], 'card.png', { type: 'image/png' });
  // Upload file with your application's HTTP client.
}, 'image/png');

Encoding can fail or produce an unusable result if the canvas has been tainted by cross-origin content. Resolve the image-origin issue before treating export as reliable.

Set options for cropping, transparency, and cleanup

Pass a second options object to tailor the render. For an element whose content extends beyond its visible box, the windowWidth and windowHeight settings can use its scroll dimensions; the html2canvas FAQ recommends this approach for clipped content (html2canvas: FAQ).

const element = this.captureRoot().nativeElement;
const canvas = await html2canvas(element, {
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight,
  backgroundColor: null,
  onclone: clonedDocument => {
    clonedDocument.querySelectorAll('.export-hide').forEach(node => node.remove());
  }
});
  • windowWidth and windowHeight: provide a viewport size suitable for the element’s full scrollable content.
  • backgroundColor: set to null when a transparent background is appropriate; otherwise choose a solid color if the default page background is not what you want.
  • onclone: adjust the cloned document for capture, for example removing controls or applying export-only styles, without changing the live component.
  • canvas: supply an existing canvas as the render target if your integration needs one.
  • cullOffscreen: control whether offscreen elements are culled during rendering.

These options are listed in the project’s configuration reference (html2canvas: Configuration). Use clone changes for presentation cleanup rather than mutating the live Angular view just to take an image.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for images, fonts, and other assets

A render callback means Angular has rendered its view; it does not mean every external image or font has finished loading. An export started too early can use fallback fonts or omit an image. Make asset readiness part of the capture flow when the component depends on asynchronous resources.

async function waitForImages(root: HTMLElement): Promise<void> {
  const images = Array.from(root.querySelectorAll('img'));
  await Promise.all(images.map(image => {
    if (image.complete) return Promise.resolve();
    return new Promise<void>(resolve => {
      image.addEventListener('load', () => resolve(), { once: true });
      image.addEventListener('error', () => resolve(), { once: true });
    });
  }));

  if ('fonts' in document) {
    await document.fonts.ready;
  }
}

Call this with the target element before invoking html2canvas. The helper resolves on image errors as well as successful loads to avoid hanging forever; if missing images are unacceptable, track failures separately and show an export error instead of silently proceeding.

Rank #3
Sale
XPPen Deco 01 V3 10x6 Drawing Tablet, 16K Battery-Free Stylus, 8 Keys
  • Word-first 16K Pressure Levels: The upgraded stylus features 16,384 levels of pressure sensitivity and supports up to 60 degrees of tilt, delivering smoother lines and shading for a natural drawing experience. With no battery or charging needed, it operates like a real pen, making it easy for beginners to create effortlessly. This functionality helps novice artists develop their skills and explore their creativity without the intimidation of complex tools
  • Designed for Beginners: This drawing pad desinged with 8 customizable shortcuts for both right and left-hand users, express keys create a highly ergonomic and convenient work platform
  • Perfectly Adapted for Android: The XPPen Deco 01 V3 art tablet supports connections with Android devices running version 10.0 and above. It is recommended to download the XPPen Tools Android application, which adapts to your smartphone's screen aspect ratio, ensuring accurate mapping. It also supports mapping on Android screens with different aspect ratios in portrait mode
  • Large Drawing Space, Bigger Bold Inspiration: This expansive drawing pad has10 x 6.25-inch helps you break through the limit between shortcut keys and drawing area
  • Easy Connectivity for Beginners: The Deco 01 V3 offers USB-C to USB-C connectivity, plus adapters for USB C. This ensures easy connection to various devices, allowing beginner artists to set up quickly and focus on their creativity without compatibility concerns. Whether using a laptop, tablet, or desktop, the Deco 01 V3 provides a seamless experience, making it an ideal choice for those just starting their digital art journey

Handle cross-origin images and iframe content

An image loaded from another origin can taint the canvas unless its server permits the relevant cross-origin access. Setting useCORS: true asks html2canvas to load images using CORS, but it only works when the image server sends a matching Access-Control-Allow-Origin response header. Otherwise, arrange for the server to allow your origin or use a proxy that makes the image available same-origin (html2canvas: Proxy).

const canvas = await html2canvas(element, {
  useCORS: true,
  windowWidth: element.scrollWidth,
  windowHeight: element.scrollHeight
});

Do not treat useCORS as a way to bypass browser security policy: it cannot grant permission the remote server has not supplied. Cross-origin iframe documents are another boundary. The browser does not expose their document contents to the parent page, so html2canvas cannot recursively render those documents (html2canvas: Documentation).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capture dynamically created components

When a component is created dynamically, capture its inserted host element or an enclosing wrapper after Angular has rendered it. Angular supports NgComponentOutlet and ViewContainerRef for dynamic component composition. For a component created outside the regular view hierarchy, Angular’s standalone createComponent API accepts an explicit host element and returns a ComponentRef; attach the view to ApplicationRef when required, then capture after rendering (Angular: Programmatic rendering).

This pattern is useful for export-only instances: create the component in a dedicated wrapper, provide its inputs, attach it where Angular can render it, wait for the render callback and required assets, and pass the wrapper’s DOM node to html2canvas. Keep creation and teardown paired so temporary views do not remain attached after the export completes.

Keep capture browser-only in Angular SSR applications

html2canvas depends on browser globals such as window, document, and computed styles. Do not import or execute capture logic as though it could render on the server. Angular’s render callbacks do not run during SSR or build-time prerendering, and Angular says Renderer2 DOM APIs do not support those contexts either (Angular component lifecycle; Angular Renderer2 API).

Rank #4
Sale
HUION Inspiroy H1060P Graphics Drawing Tablet, 10 x 6.25 in, 12+16 Hot Keys
  • Working Area Configuration - HUION art tablet equips with a 10 x 6.25 inches working area, providing the user with the most comfortable size to work; the 10mm slim structure and minimalist design of appearance make the drawing tablet more attractive.
  • Tilt Function Battery-free Stylus: This computer graphics tablet come with a battery-free stylus PW100, no need to charge, allowing for constant uninterrupted drawing. ±60° tilt support enables imitation of lines input with diverse drawing gestures, with accuracy ensured.
  • Press Keys:12 programmable press keys plus 16 programmable soft keys, you can set shortcut keys on drawing tablet's driver based on your preferences, such as erase, zoom in/out, scroll up and down, and so on.
  • Compatibility: HUION graphics tablet supports Windows 7 or later/ macOS 10.12 or later/ Android 6.0 or later/ Linux (Ubuntu). A USB adapter is required to connect to a Mac computer. H1060P supports various mainstream design and drawing software, including PS, SAI, AI, CDR, etc. (Please note: The H1060P is compatible with Ubuntu, but it requires the use of the Xorg display server. Wayland is not supported.)
  • NOTE: You can easily connect your phone to the art tablet via the OTG connector; while iPhone and iPad are NOT at the moment. The cursor will not show up in the SAMSUNG Galaxy S series at present. If you are not sure whether the product is compatible with your Phone or any help, please contact us.

Keep the capture path behind the browser-only checks already used by your application and run it after client rendering or hydration. Prefer template bindings and Angular APIs for component structure; ElementRef is appropriate here because a third-party renderer needs the actual element, but direct DOM manipulation should not replace Angular’s normal template and binding model.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Know when a canvas export is too large

Browsers and hardware impose canvas dimension and memory limits, and there is no single maximum that applies to every environment. A very large capture may fail, become blank, or be partial. Start with the element’s scroll dimensions to address clipping, then reduce output scale or split a long report into smaller sections if the capture still exceeds platform limits. The html2canvas FAQ discusses these browser-dependent limits and failure modes (html2canvas: FAQ).

For long documents, section-by-section export usually has a better failure profile than one enormous bitmap. It also makes it easier to retry a failed section without regenerating the entire document.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot blank, cropped, or inaccurate output

  • The result is blank: Confirm the element exists in the browser when capture runs, that the capture code is not being executed on the server, and that rendering has completed. Check the promise rejection in the console rather than suppressing errors.
  • The bottom or sides are cropped: Pass the target element’s scrollWidth and scrollHeight as windowWidth and windowHeight. If a huge capture remains incomplete, reduce scale or split the content.
  • Images disappear or encoding fails: Wait for the images, enable useCORS only when the image host supplies the required CORS header, or serve them through a suitable same-origin proxy.
  • Fonts or layout differ: Wait for document.fonts.ready and other asynchronous assets. Remember that supported DOM/CSS is reconstructed, not copied from browser pixels.
  • Content inside an iframe is missing: A cross-origin frame is isolated by browser security. Capture that content in the frame’s own context or use a real browser screenshot approach with suitable access.
  • SSR reports window or document errors: Move the call into a browser-only path and invoke it after client rendering; do not run it during prerendering.

Or skip the browser setup

If the goal is to capture a rendered page rather than generate a bitmap inside the Angular app, ScreenshotNeo is a website screenshot API and MCP server. It can return a PNG, JPEG, WebP, or PDF from one request. Unlike html2canvas, it captures a rendered browser page, which can be useful when CSS fidelity or a server-side workflow matters; it does not turn an Angular component into an in-app canvas.

For a URL reachable by the service, this cURL request saves a WebP screenshot:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
HUION Inspiroy H640P 6x4 inch Drawing Tablet 8192 Pen Pressure
  • Customize Your Workflow: The 6 customizable press keys on Huion H640P drawing tablet for pc let you assign your most-used commands—like undo, zoom, brush switch, or save—so you can keep your hands on the tablet and your mind on the art. Whether you're a digital painter switching brushes, or a comic artist zooming in and out, these keys keep your workflow smooth and uninterrupted. Plus, the Huion driver lets you save different shortcut profiles for different apps, so you never have to reconfigure when switching software.
  • Professional Pen Performance: Huion H640P drawing pad for computer comes with the battery-free PW100 stylus that's always ready when inspiration strikes. With 8192 levels of pressure sensitivity, every light sketch, or bold stroke responds naturally to your hand—just like a real pen. The 5080 LPI resolution and 233 PPS report rate deliver lag-free, precise strokes, so you can draw confidently without second-guessing your cursor. The pen side buttons help you switch between pen and eraser instantly.
  • Compact and Portable: Huion H640P computer graphics tablet features a compact, ultra-portable design at just 0.3 inches thin and 0.61 lbs light, so it slides easily into your backpack—perfect for sketching in coffee shops, taking notes in class, or editing on the go between home and studio. The 6x4 inch active area offers enough room for natural pen movements while fitting comfortably on crowded desks, or lecture hall seats.
  • Stable Compatibility: Huion H640P graphic drawing tablet works seamlessly with Mac, Windows, Linux PCs, and Android smartphones/tablets (OS version 6.0 or later). Left-handed friendly, and you just need to flip the tablet and adjust the settings in the driver. Please note: H640P does NOT support iPhone/iPad.
  • Move Beyond the Mouse: Huion Inspiroy H640P is a pen tablet that replaces your mouse for more natural, precise control. Freehand draw, take notes, or even play OSU—everything you do with a mouse, you can do better with a pen. The precise tip makes it ideal for detailed photo editing, graphic design, or signing PDF. Meanwhile, the ergonomic pen grip helps you avoid the strain that comes from hours of using a mouse.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for authentication and available request parameters. Cookie banners, newsletter popups, and chat widgets are removed before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up free for ScreenshotNeo to try 1,000 screenshots a month without a credit card.

FAQ

Can I render an Angular component to canvas without html2canvas?

Yes, but the alternative depends on what you mean by render. A real browser screenshot captures rendered pixels through a browser automation or screenshot service; a canvas library reconstructs the element from DOM and styles. For a client-side canvas in an Angular page, html2canvas is the method shown here.

Can html2canvas export a component to PDF?

html2canvas produces a canvas, not a PDF document. A PDF workflow needs an additional PDF-generation step or a browser-based PDF capture approach.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does html2canvas capture a component that is hidden?

It needs a rendered DOM element with layout and styles to reconstruct. Temporarily hiding an element in a way that removes its layout can leave nothing useful to capture; use an export wrapper or clone-specific styling instead.

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.