KScript 문서
KO

언어

영어에서 자동 번역되었습니다. 원문은 영어입니다.

문서: KScript.Document

문서 저장하기

블록이 끝나면 to:이(가) 문서를 저장해요. 확장자가 형식을 결정하고, 경로 목록을 지정하면 여러 형식으로 저장해요:

<KScript.Document title="Notes" to="notes.pdf, notes.docx, notes.tex">
  <Paragraph>Saved three ways.</Paragraph>
</KScript.Document>
import KScript.Document

Document(title: 'Notes', to: ['notes.pdf', 'notes.docx', 'notes.tex']) {
  Paragraph "Saved three ways."
}
확장 결과물
.pdf KScript가 레이아웃을 잡은 PDF입니다. 페이지 번호, 클릭할 수 있는 목차와 북마크, 링크, 이미지를 포함합니다.
.docx 실제 제목, 번호 매기기 목록, 각주, Word에서 편집할 수 있는 수식, 그리고 Word가 채워 주는 목차가 있는 Word 문서입니다.
.tex pdflatex를 위한 LaTeX 파일로, \section, \label/\ref, amsmath, booktabs 및 \bibitem을(를) 포함합니다. 이미지는 경로로 참조합니다.
.md $...$수식, GitHub 표, 각주를 지원하는 Markdown입니다.
.html HTML 페이지 하나에 스타일, MathML 수식, 이미지가 모두 들어 있어요.

into:는 대신 (또는 함께) 문서를 변수에 보관하므로, 나중에 저장하거나 텍스트로 변환할 수 있어요:

<import package="KScript.Document" />

<Document title="Report" into="doc">
  <Paragraph>Hello.</Paragraph>
</Document>
<do>$doc->save('report.pdf')</do>
<echo>{ $doc->pages() } pages, { $doc->words() } words</echo>
import KScript.Document

Document(title: 'Report', into: doc) {
  Paragraph "Hello."
}
$doc->save('report.pdf')
echo "{ $doc->pages() } pages, { $doc->words() } words"
메서드 기능
->save(path, as?) 파일 확장자 또는 as:에서 선택한 형식으로 저장해요.
->pages() PDF에 있는 페이지 수입니다.
->words() 텍스트에 수학 기호와 코드를 제외하고 단어가 몇 개인지 나타냅니다.
->convert(to: markdown), ->convert(to: latex) 및 ->convert(to: html) 인쇄하거나, 보내거나, 직접 저장할 수 있는 텍스트 형식의 문서입니다.
->bytes(as: pdf|docx|html) 파일을 쓰지 않고, 렌더링된 파일을 base64 값으로 반환해요.

$doc.title은(는) 제목이에요.

라우트는 문서를 먼저 저장하지 않고도 보낼 수 있어요. ->bytes(as: pdf)은 메모리에서 문서를 렌더링하고, @response()는 바이트를 보내요:

<import package="KScript.Http" />
<import package="KScript.Document" />

<fn name="invoice" params="id: int">
  <Document title="Invoice { $id }" into="doc">
    <Paragraph>Thank you for your order.</Paragraph>
  </Document>
  <return value="@response($doc->bytes(as: pdf), type: 'application/pdf', headers: { 'Content-Disposition': &quot;inline; filename=invoice-{ $id }.pdf&quot; })" />
</fn>
import KScript.Http
import KScript.Document

fn invoice(id: int) {
  Document(title: "Invoice { $id }", into: doc) {
    Paragraph "Thank you for your order."
  }
  return @response($doc->bytes(as: pdf), type: 'application/pdf', headers: { 'Content-Disposition': "inline; filename=invoice-{ $id }.pdf" })
}