How to use the pdf-lib.PDFName.of function in pdf-lib

To help you get started, we’ve selected a few pdf-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
async function addOutline (pdfDoc, doc) {
  const depth = doc.getAttribute('toclevels') || 2
  const context = pdfDoc.context
  const outlineRef = context.nextRef()

  const outline = getOutline(doc, depth)
  if (outline.length === 0) {
    return pdfDoc
  }
  generateWarningsAboutMissingDestinations(outline, pdfDoc)
  setRefsForOutlineItems(outline, context, outlineRef)
  buildPdfObjectsForOutline(outline, context)

  const outlineObject = PDFDict.fromMapWithContext(new Map([
    [PDFName.of('First'), outline[0].ref],
    [PDFName.of('Last'), outline[outline.length - 1].ref],
    [PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(outline))]
  ]), context)
  context.assign(outlineRef, outlineObject)

  pdfDoc.catalog.set(PDFName.of('Outlines'), outlineRef)
  return pdfDoc
}
github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
const next = layer[i + 1]

    const pdfObject = new Map([
      [PDFName.of('Title'), PDFHexString.fromText(item.title)],
      [PDFName.of('Dest'), PDFName.of(item.destination)],
      [PDFName.of('Parent'), item.parentRef]
    ])
    if (prev) {
      pdfObject.set(PDFName.of('Prev'), prev.ref)
    }
    if (next) {
      pdfObject.set(PDFName.of('Next'), next.ref)
    }
    if (item.children.length > 0) {
      pdfObject.set(PDFName.of('First'), item.children[0].ref)
      pdfObject.set(PDFName.of('Last'), item.children[item.children.length - 1].ref)
      pdfObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(item.children)))
    }

    context.assign(item.ref, PDFDict.fromMapWithContext(pdfObject, context))

    buildPdfObjectsForOutline(item.children, context)
  }
}
github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
function buildPdfObjectsForOutline (layer, context) {
  for (const [i, item] of layer.entries()) {
    const prev = layer[i - 1]
    const next = layer[i + 1]

    const pdfObject = new Map([
      [PDFName.of('Title'), PDFHexString.fromText(item.title)],
      [PDFName.of('Dest'), PDFName.of(item.destination)],
      [PDFName.of('Parent'), item.parentRef]
    ])
    if (prev) {
      pdfObject.set(PDFName.of('Prev'), prev.ref)
    }
    if (next) {
      pdfObject.set(PDFName.of('Next'), next.ref)
    }
    if (item.children.length > 0) {
      pdfObject.set(PDFName.of('First'), item.children[0].ref)
      pdfObject.set(PDFName.of('Last'), item.children[item.children.length - 1].ref)
      pdfObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(item.children)))
    }

    context.assign(item.ref, PDFDict.fromMapWithContext(pdfObject, context))

    buildPdfObjectsForOutline(item.children, context)
github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
async function addOutline (pdfDoc, doc) {
  const depth = doc.getAttribute('toclevels') || 2
  const context = pdfDoc.context
  const outlineRef = context.nextRef()

  const outline = getOutline(doc, depth)
  if (outline.length === 0) {
    return pdfDoc
  }
  generateWarningsAboutMissingDestinations(outline, pdfDoc)
  setRefsForOutlineItems(outline, context, outlineRef)
  buildPdfObjectsForOutline(outline, context)

  const outlineObject = PDFDict.fromMapWithContext(new Map([
    [PDFName.of('First'), outline[0].ref],
    [PDFName.of('Last'), outline[outline.length - 1].ref],
    [PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(outline))]
  ]), context)
  context.assign(outlineRef, outlineObject)

  pdfDoc.catalog.set(PDFName.of('Outlines'), outlineRef)
  return pdfDoc
}
github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
function buildPdfObjectsForOutline (layer, context) {
  for (const [i, item] of layer.entries()) {
    const prev = layer[i - 1]
    const next = layer[i + 1]

    const pdfObject = new Map([
      [PDFName.of('Title'), PDFHexString.fromText(item.title)],
      [PDFName.of('Dest'), PDFName.of(item.destination)],
      [PDFName.of('Parent'), item.parentRef]
    ])
    if (prev) {
      pdfObject.set(PDFName.of('Prev'), prev.ref)
    }
    if (next) {
      pdfObject.set(PDFName.of('Next'), next.ref)
    }
    if (item.children.length > 0) {
      pdfObject.set(PDFName.of('First'), item.children[0].ref)
      pdfObject.set(PDFName.of('Last'), item.children[item.children.length - 1].ref)
      pdfObject.set(PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(item.children)))
    }

    context.assign(item.ref, PDFDict.fromMapWithContext(pdfObject, context))
github Mogztter / asciidoctor-pdf.js / lib / outline.js View on Github external
const outline = getOutline(doc, depth)
  if (outline.length === 0) {
    return pdfDoc
  }
  generateWarningsAboutMissingDestinations(outline, pdfDoc)
  setRefsForOutlineItems(outline, context, outlineRef)
  buildPdfObjectsForOutline(outline, context)

  const outlineObject = PDFDict.fromMapWithContext(new Map([
    [PDFName.of('First'), outline[0].ref],
    [PDFName.of('Last'), outline[outline.length - 1].ref],
    [PDFName.of('Count'), PDFNumber.of(countChildrenOfOutline(outline))]
  ]), context)
  context.assign(outlineRef, outlineObject)

  pdfDoc.catalog.set(PDFName.of('Outlines'), outlineRef)
  return pdfDoc
}