Skip to content

html2pdfExt 扩展参考 ​

原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793325189/FIN+5.3.1+html2pdfExt 中文整理基于 FIN 5.3.1

导读: Axon 扩展库,用于将网页转换为 PDF。

以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。


目录(导读) ​

  • classes
  • Slot Details
    • make
    • mapUrl
    • resolveURI
    • urlHash
    • getContent
    • setReqHeader
    • finPrintPdf
    • pdfs
    • agent
    • begin
    • convert
    • createTempDir
    • downloadFile
    • end
    • findReplace
    • generateUniqueName
    • getContentsOfHref
    • getName
    • getPageCss
    • getUrlHash
    • logger
    • os
    • pixelToMM
    • preprocess
    • preprocessCssImg
    • process
    • processPage
    • renderer
    • setHeaderFooter
    • targetPdf
    • templates
    • tmpDir
    • tmpPdf
    • toJavaFile
    • writeToFile
    • eventListener
    • onClose
    • preOpen
    • calcHeight
    • getClassName
    • getDefaultStyleSheet
    • getTableFromTemplate
    • removeBlankPages
    • stampHeaderFooter

概述(中译) ​

类 BrowserAgent : ITextUserAgent

构造函数

字段

方法

插槽详情

new make(ITextOutputDevice? 输出设备)


API 正文(英文) ​

mapUrl ​

Void mapUrl(Str remoteUrl, Str localUrl)


resolveURI ​

virtual override Str? resolveURI(Str? uri)


urlHash ​

Str:Str urlHash := [Str:Str][:]


GzipWebClient ​

class GzipWebClient : WebClient

Constructors

make

Methods

getContent
setReqHeader

Slot Details ​


getContent ​

Str getContent()


make ​

new make(Str uri)


setReqHeader ​

Void setReqHeader(Str key, Str value)


HtmlpdfExt ​

@ExtMeta { name="html2pdf" } @FinExtMeta { licFeature="finstack"; pngIcon=`fan://finStackExt/res/img/fins_24.png` } const class HtmlpdfExt : FinExt, Weblet

Htmlpdf Extension

Slot Details ​


HtmlpdfLib ​

const class HtmlpdfLib : Obj

Axon functions for htmlpdf

Fields

pdfs

Methods

finPrintPdfdownload and convert web pages into 1 pdf.

Slot Details ​


finPrintPdf ​

@Axon static File finPrintPdf(Str[] pages, Str headerXml, Str footerXml, Uri? pdfPath := null)

download and convert web pages into 1 pdf. Return path to the result pdf


pdfs ​

const static File pdfs := Env.cur().homeDir().plus(`pub/pdfs/`)


PdfEngine ​

class PdfEngine : Obj

Constructors

makeconstructor

Fields

agent
logger
os
renderer
targetPdf
templates
tmpDir
tmpPdf

Methods

begin
convert
createTempDir
downloadFile
end
findReplace
generateUniqueName
getContentsOfHref
getName
getPageCss
getUrlHash
pixelToMM
preprocess
preprocessCssImg
process
processPage
setHeaderFooterset the header and footer html template for the pdf
toJavaFile
writeToFile

Slot Details ​


agent ​

BrowserAgent agent


begin ​

Void begin()


convert ​

protected Void convert(Str uri)


createTempDir ​

static File? createTempDir()


downloadFile ​

protected Str downloadFile(Str src, File folder)


end ​

Void end()


findReplace ​

protected Str findReplace(Str text, Regex regex, Str replace)


generateUniqueName ​

static Str generateUniqueName(Str proposed)


getContentsOfHref ​

static Str getContentsOfHref(Str src)


getName ​

protected Str getName(Str url)


getPageCss ​

protected Str getPageCss()


getUrlHash ​

protected Str:Str getUrlHash()


logger ​

const static Log logger := Log.get("PdfEngine")


make ​

new make(Str targetUrl)

constructor


os ​

OutputStream? os


pixelToMM ​

protected Float pixelToMM(Float pixel)


preprocess ​

protected File? preprocess(Str url)


preprocessCssImg ​

protected Void preprocessCssImg(Str css, Str orgUrl, File? dir)


process ​

Void process(Str[] urls)


processPage ​

Void processPage(Str url)


renderer ​

ITextRenderer renderer


setHeaderFooter ​

Void setHeaderFooter(Str headerTpl, Str footerTpl)

set the header and footer html template for the pdf


targetPdf ​

File? targetPdf


templates ​

Str[] templates := Str["",""]


tmpDir ​

File? tmpDir


tmpPdf ​

File? tmpPdf


toJavaFile ​

protected File toJavaFile(File f)


writeToFile ​

protected Void writeToFile(Str url, Str content)


PdfEventListener ​

class PdfEventListener : DefaultPDFCreationListener

Constructors

make

Fields

eventListener

Methods

onClose
preOpen

Slot Details ​


eventListener ​

PdfPageEventHelper? eventListener


make ​

new make(PdfPageEventHelper listener)


onClose ​

virtual override Void onClose(ITextRenderer? renderer)


preOpen ​

virtual override Void preOpen(ITextRenderer? iTextRenderer)


PdfUtils ​

class PdfUtils : Obj

Fields

logger

Methods

calcHeight
getClassName
getDefaultStyleSheet
getTableFromTemplate
removeBlankPages
stampHeaderFooter

Slot Details ​


calcHeight ​

static Float calcHeight(Str tpl, Float proposedWidth)


getClassName ​

static Str getClassName(Obj obj)


getDefaultStyleSheet ​

protected static StyleSheet? getDefaultStyleSheet()


getTableFromTemplate ​

protected static PdfPTable getTableFromTemplate(Str tpl, Float proposedWidth)


logger ​

const static Log logger := Log.get("PdfHeaderFooterStamper")


removeBlankPages ​

static Bool removeBlankPages(Str inFile, Str outFile)


stampHeaderFooter ​

static Void stampHeaderFooter(Str srcPath, Str targetPath, Str? headerTpl, Str? footerTpl)