
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@codewithrajat/rm-ng-pdf-export
Advanced tools
Angular library for exporting HTML content to PDF using html2canvas and pdf-lib with smart page breaking and ultra-high-quality rendering
@codewithrajat/rm-ng-pdf-export is a lightweight, flexible, and tree-shakable Angular library for generating and exporting ultra-high-quality PDFs from HTML content with smart page breaking and crystal-clear rendering. Built with modern Angular (v14–v20), it seamlessly integrates with your application using services, directives, and components.
Note:
This library is intended for generating non-editable, read-only PDFs.
If you need to create structured, searchable, and editable PDFs, please use our other library: @codewithrajat/rm-ng-structure-pdf.
html2canvas and pdf-libpage-break-before, page-break-after, and page-break-inside properties[rmPdfExport]), or Component (<rm-pdf-export>)isPlatformBrowser)Install via npm:
npm install @codewithrajat/rm-ng-pdf-export
📋 Peer Dependencies
| Library | Version |
|---|---|
| @angular/core | ^14.0.0–^20.0.0 |
| pdf-lib | ^1.17.1 |
| html2canvas | ^1.4.1 |
Install missing dependencies if needed:
npm install pdf-lib html2canvas
🧭 Compatibility Matrix
| Angular Version | Compatible | Standalone Support |
|---|---|---|
| 14 | ✅ | ❌ (partial) |
| 15 | ✅ | ✅ |
| 16 | ✅ | ✅ |
| 17 | ✅ | ✅ |
| 18–20 | ✅ | ✅ |
The library follows the Angular Package Format (APF) and supports both ViewEngine and Ivy compilation.
🧪 Usage
Import providers in main.ts :
// in case of adding in root
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { PdfExportService, PDF_EXPORT_CONFIG } from '@codewithrajat/rm-ng-pdf-export';
bootstrapApplication(AppComponent, {
providers: [
PdfExportService,
{
provide: PDF_EXPORT_CONFIG,
useValue: {
filename: 'export.pdf',
orientation: 'portrait',
openInNewTab: false
}
}
]
});
Import providers in component.ts (if using standalone and do not want to import globally like main.ts):
// in case of adding in component
import { Component, ElementRef, ViewChild } from '@angular/core';
import { PdfExportService, PDF_EXPORT_CONFIG } from '@codewithrajat/rm-ng-pdf-export';
@Component({
selector: 'app-report',
standalone: true,
templateUrl: './report.component.html',
styleUrls: ['./report.component.scss'],
providers: [
PdfExportService,
{
provide: PDF_EXPORT_CONFIG,
useValue: {
filename: 'report.pdf',
orientation: 'landscape',
openInNewTab: true
}
}
]
})
export class ReportComponent {
constructor(private pdfExport: PdfExportService) {}
@ViewChild('pdfContent') contentRef!: ElementRef;
export() {
this.pdfExport.exportHtml(this.contentRef.nativeElement, { filename: 'one.pdf' });
}
}
Use in component:
<div #pdfContent>
<h1>Invoice</h1>
<p>Product list, totals, etc.</p>
</div>
<button (click)="export()">Export PDF</button>
@ViewChild('pdfContent') contentRef!: ElementRef;
constructor(private pdfService: PdfExportService) {}
export() {
this.pdfService.exportHtml(this.contentRef.nativeElement, { filename: 'one.pdf' });
}
<div #pdfContent>Invoice body here</div>
<button
rmPdfExport
[pdfConfig]="{ filename: 'invoice.pdf' }"
[exportTarget]="pdfContent">
Export as PDF
</button>
⚙️ Advanced Configuration
| Option | Description |
|---|---|
| filename | Custom filename for the download |
| orientation | 'portrait' or 'landscape' |
| pageSize | 'A4', 'LETTER', 'LEGAL', etc. |
| metadata.title | Sets the PDF document title |
| metadata.author | Sets author info |
| openInNewTab | true opens PDF in a new tab instead of download |
Example:
{
filename: 'summary.pdf',
orientation: 'landscape',
metadata: {
title: 'Sales Summary',
author: 'Analytics Team'
},
openInNewTab: true
}
📘 API Reference
PdfExportService
exportHtml(element: HTMLElement, overrideConfig?: PdfExportConfig): Promise<void>;
PDF_EXPORT_CONFIG
An InjectionToken<PdfExportConfig> for global config defaults.
🌳 Tree-Shaking and Optimization
sideEffects: false in package.jsonpdf-lib or html2canvas until explicitly needed⚠️ Known Issues & Limitations
html2canvas does not support modern CSS functions like oklch() or color()🛠 Development Setup (for contributors)
git clone https://github.com/malikrajat/@codewithrajat/rm-ng-pdf-export.git
cd rm-ng-pdf-export
npm install
Scripts
| Command | Description |
|---|---|
| npm run build | Builds the library using ng-packagr |
| npm run test | Runs unit tests with Jest |
| npm run lint | Lints the codebase |
Folder Structure
projects/
rm-ng-pdf-export/
src/
lib/
directives/
services/
tokens/
components/
public-api.ts
ng-package.json
📦 Release Notes / Changelog
See CHANGELOG.md for detailed version history.
📄 License
This project is licensed under the MIT License.
👤 Author / Maintainer Info
Rajat Malik Frontend Developer | Open Source Contributor
🙏 Credits & Acknowledgements
Built with ❤️ for the Angular community.
FAQs
Angular library for exporting HTML content to PDF using html2canvas and pdf-lib with smart page breaking and ultra-high-quality rendering
We found that @codewithrajat/rm-ng-pdf-export demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.