Skip to content

Commit

Permalink
feat(pdf-generator): add new pluign (#3268)
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 authored and danielsogl committed Dec 27, 2019
1 parent a74c894 commit 3f1fa37
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/@ionic-native/plugins/pdf-generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Injectable } from '@angular/core';
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';

export interface PDFGeneratorOptions {
/**
* The document size, e.g., A2, A3, or A4.
* Only supported on iOS.
* The default is 'A4'.
*/
documentSize?: string;

/**
* Option to change to landscape orientation.
* Default is 'portrait'.
*/
landscape?: 'landscape' | 'portrait';

/**
* The type to be returned, either 'share' or 'base64'.
* If 'share is chosen, the PDF is shared with the system capabilities.
* Default is 'base64'
*/
type?: string;

/**
* The desired filename the resulting PDF should have.
* Default is 'default.pdf'
*/
fileName?: string;

/**
* Option to set the base URL for pathing.
* Default is 'null'.
*/
baseUrl?: string;
}

/**
* @name PDFGenerator
* @description
* Simple plugin to generate (offline) pdf. The plugin transforms HTML to PDF and also provide the mechanism to share the pdf to other apps like Mail, etc.
*
* @usage
* ```typescript
* import { PDFGenerator } from '@ionic-native/pdf-generator';
*
* constructor(private pdfGenerator: PDFGenerator) { }
*
* ...
*
* this.pdfGenerator.fromURL(url, options).then(base64String => console.log(base64String));
*
* ```
*/
@Plugin({
pluginName: 'PDFGenerator',
plugin: 'cordova-pdf-generator',
pluginRef: 'cordova.plugins.pdf',
repo: 'https://github.com/cesarvr/pdf-generator',
platforms: ['Android', 'iOS']
})
@Injectable({
providedIn: 'root'
})
export class PDFGenerator extends IonicNativePlugin {
/**
* Creates a PDF using a URL, it download the document into an in memory Webkit object, and renders it into a PDF.
* @param url {string} URL to create a PDF from
* @param options {PDFGeneratorOptions} options for PDF generation
* @returns {Promise<string>}
*/
@Cordova({ otherPromise: true })
fromURL(url: string, options?: PDFGeneratorOptions): Promise<string> {
return;
}

/**
* Creates a PDF using string with the HTML representation, it download the document into an in memory Webkit object, and renders it into a PDF.
* @param data {string} HTML string representation to create a PDF from
* @param options {PDFGeneratorOptions} options for PDF generation
* @returns {Promise<string>}
*/
@Cordova({ otherPromise: true })
fromData(data: string, options?: PDFGeneratorOptions): Promise<string> {
return;
}
}

1 comment on commit 3f1fa37

@lucrus73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About line 47 of this commit, VSCode warns: 'PDFGenerator' refers to a value, but is being used as a type here.ts(2749). Maybe it's my fault, but I don't know what to do next.

Please sign in to comment.