npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ticnat/nativescript-page-to-pdf

v1.0.1

Published

Export NativeScript Page/View to PDF (Android & iOS)

Readme

@ticnat/nativescript-page-to-pdf

Export any NativeScript Page or View (including complex layouts with charts) to a single-page PDF on Android and iOS.

  • ✅ Android: PdfDocument + Canvas.draw
  • ✅ iOS: UIGraphicsPDFRenderer
  • ✅ Works with on-screen views (recommended)
  • ✅ No native configuration required

Installation

npm install @ticnat/nativescript-page-to-pdf

API

export function exportViewToPdf(
  view: View,
  options?: ExportPdfOptions
): Promise<{ filePath: string }>;

ExportPdfOptions

| Option | Type | Description | |------|------|-------------| | fileName | string | Output file name (e.g. report.pdf) | | outputFolder | string | Folder path (defaults to app Documents folder) | | ensureLayout | boolean | Forces layout before export (useful if view size is 0) | | backgroundColor | number \| UIColor | Optional background fill | | openAfterSave | boolean | Open the generated PDF right after saving | | mimeType | string | Android only: MIME type when opening (default application/pdf) |


Usage — NativeScript Core

Export the current page

import { Frame } from '@nativescript/core';
import { exportViewToPdf } from '@ticnat/nativescript-page-to-pdf';

const page = Frame.topmost().currentPage;

const result = await exportViewToPdf(page.content, {
  fileName: 'page-export.pdf',
  ensureLayout: true
});

console.log('PDF saved at:', result.filePath);

Export a specific view (e.g. chart container)

import { exportViewToPdf } from '@ticnat/nativescript-page-to-pdf';

const view = page.getViewById('chartContainer');

await exportViewToPdf(view, {
  fileName: 'chart.pdf'
});

Export + open the PDF right after saving

import { exportViewToPdf } from '@ticnat/nativescript-page-to-pdf';

await exportViewToPdf(view, {
  fileName: 'demo.pdf',
  ensureLayout: true,
  openAfterSave: true
});

Usage — NativeScript Angular

Component example

import { Component } from '@angular/core';
import { Frame } from '@nativescript/core';
import { exportViewToPdf } from '@ticnat/nativescript-page-to-pdf';

@Component({
  selector: 'demo',
  template: `
    <StackLayout>
      <GridLayout id="pdfContent">
        <!-- charts / content -->
      </GridLayout>

      <Button text="Export to PDF" (tap)="export()" />
    </StackLayout>
  `
})
export class DemoComponent {
  async export() {
    const page = Frame.topmost().currentPage;
    const view = page.getViewById('pdfContent');

    const res = await exportViewToPdf(view, {
      fileName: 'angular-view.pdf',
      ensureLayout: true,
      openAfterSave: true
    });

    console.log('PDF saved at:', res.filePath);
  }
}

Android: required FileProvider setup (for openAfterSave)

When openAfterSave: true, Android must open the PDF using a content:// URI. If your app does not already include a FileProvider, you’ll get FileUriExposedException.

Where to add it (your plugin seed structure)

In your NativeScript app add these changes in your App_Resources folder under:

  • App_Resources/Android/src/main/AndroidManifest.xml
  • App_Resources/Android/src/main/res/xml/file_paths.xml // create one if not exist

(If your app uses App_Resources directly under the app, use that path instead.)

1) Create file_paths.xml

Create this file:

App_Resources/Android/src/main/res/xml/file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- /data/user/0/<package>/files/... -->
  <files-path name="files" path="." />
  <!-- optional -->
  <cache-path name="cache" path="." />
  <external-files-path name="external_files" path="." />
</paths>

2) Add the provider inside <application> (before <activity>)

Edit:

tools/assets/App_Resources/Android/src/main/AndroidManifest.xml

Inside the <application ...> tag, add:

<provider
  android:name="androidx.core.content.FileProvider"
  android:authorities="${applicationId}.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/file_paths" />
</provider>

3) Rebuild clean (platform folder is generated)

If you still see “No app found to open PDF”, install a PDF viewer on the device/emulator.


Notes & Best Practices

  • ✅ Best results when exporting a view that is already visible on screen
  • 📊 Chart libraries usually render correctly via drawViewHierarchyInRect
  • 📄 This plugin currently exports one PDF page
  • 🧩 Long scroll views / multi-page PDFs can be added later

Platform Details

Android

  • Uses android.graphics.pdf.PdfDocument
  • Output location: app Documents folder
  • Resolution equals the view’s pixel size

iOS

  • Uses UIGraphicsPDFRenderer
  • Automatically handles Retina scaling

License

MIT