-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pdf-generator): add new pluign (#3268)
- Loading branch information
1 parent
a74c894
commit 3f1fa37
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
3f1fa37
There was a problem hiding this comment.
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.