tibi-docs/docs/md/server-javascript-kontext/packages/pdf.md
2023-06-03 18:07:58 +00:00

4.3 KiB

jwt

interface PdfPackage {
    /**
     * generate pdf from html
     *
     * @param html html string
     * @param options options
     *
     * @returns []byte of pdf data
     */
    fromHTML(
        html: string,
        options?: {
            copies?: number // Number of copies to print into the pdf file (default 1)
            dpi?: number // Change the dpi explicitly (this has no effect on X11 based systems)
            grayscale?: boolean // PDF will be generated in grayscale
            imageDpi?: number // When embedding images scale them down to this dpi (default 600)
            imageQuality?: number // When jpeg compressing images use this quality (default 94)
            lowQuality?: boolean // Generates lower quality pdf/ps. Useful to shrink the result document space
            marginBottom?: number // Set the page bottom margin
            marginLeft?: number // Set the page left margin (default 10mm)
            marginRight?: number // Set the page right margin (default 10mm)
            marginTop?: number // Set the page top margin
            noCollate?: boolean // Do not collate when printing multiple copies (default collate)
            noPdfCompression?: boolean // Do not use lossless compression on pdf objects
            orientation?: "Portrait" | "Landscape" // Set orientation to Landscape or Portrait (default Portrait)
            pageHeight?: number // Page height
            pageSize?: string // Set paper size to: A4, Letter, etc. (default A4)
            pageWidth?: number // Page width
            title?: string // The title of the generated pdf file (The title of the first document is used if not specified)
            // page settings
            printMediaType?: boolean // Use print media-type instead of screen
            footerCenter?: string // Centered footer text
            footerFontName?: string // Set footer font name (default Arial)
            footerFontSize?: number // Set footer font size (default 12)
            footerLeft?: string // Left aligned footer text
            footerLine?: boolean // Display line above the footer
            footerRight?: string // Right aligned footer text
            footerSpacing?: number // Spacing between footer and content in mm (default 0)
            footerHTML?: string // URL to footer html
            headerCenter?: string // Centered header text
            headerFontName?: string // Set header font name (default Arial)
            headerFontSize?: number // Set header font size (default 12)
            headerLeft?: string // Left aligned header text
            headerLine?: boolean // Display line below the header
            headerRight?: string // Right aligned header text
            headerSpacing?: number // Spacing between header and content in mm (default 0)
            headerHTML?: string // URL to header html
        }
    ): any

    /**
     * process existing pdf data
     *
     * @param command pdfcpu command
     * @param pdfData []byte of pdf data, multiple []byte as array of pdf's to merge or object with description to create
     * @param options options
     *
     * @returns []byte of new pdf data
     */
    cpu(
        command: "watermark" | "stamp" | "merge" | "rotate" | "create",
        pdfData: any | any[],
        options?: {
            pages?: (string | number)[]
            description?: {
                fontname?: string
                points?: number
                rtl?: boolean
                position?: "full" | "tl" | "tc" | "tr" | "l" | "c" | "r" | "bl" | "bc" | "br"
                offset?: string
                scalefactor?: number | string
                aligntext?: "left" | "center" | "right" | "justified"
                strokecolor?: string
                fillcolor?: string
                backgroundcolor?: string
                rotation?: number
                diagonal?: 1 | 2
                opacity?: number
                rendermode?: 0 | 1 | 2
                margins?: number | string
                border?: number | string
                url?: string
            }
            mode?: "text" | "image" | "pdf"
            bytes?: any // []byte of watermark image
            file?: string // file for pdf watermark
            text?: string // text for text watermark
            rotation?: number
        }
    ): any
}