• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is possible print the pdf from an external button?

New Here ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

I want to print my pdf from an external button, like this.

 

Arlington22506699hblm_0-1642199283790.png

 

Views

222

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2022 Jan 14, 2022

Copy link to clipboard

Copied

It's my code

 

class ViewSDKClient {
  constructor(base64File, clientId, documentId) {
    this.readyPromise = new Promise((resolve) => {
      if (window.AdobeDC) {
        resolve()
      } else {
        document.addEventListener('adobe_dc_view_sdk.ready', () => {
          resolve()
        })
      }
    })
    this.adobeDCView = undefined
    this.base64File = base64File;
    this.clientId = clientId;
    this.documentId = documentId;
  }

  ready() {
    return this.readyPromise
  }

  previewFile(divId, viewerConfig) {
    const config = {
      clientId: this.clientId,
    }
    if (divId) {
      config.divId = divId
    }

    this.adobeDCView = new window.AdobeDC.View(config)

    function base64ToArrayBuffer(base64) {
      var bin = window.atob(base64)
      var len = bin.length
      var uInt8Array = new Uint8Array(len)
      for (var i = 0; i < len; i++) {
        uInt8Array[i] = bin.charCodeAt(i)
      }
      return uInt8Array.buffer;
    }

    const previewFilePromise = this.adobeDCView.previewFile(
      {
        content: { promise: Promise.resolve(base64ToArrayBuffer(this.base64File)) },
        metaData: {fileName: this.documentId+'.pdf'},
      },
      viewerConfig,
    )

    previewFilePromise.then(adobeViewer => {
      adobeViewer.getAPIs().then(apis => {
        debugger
        apis.getPDFMetadata()
        .then(result => console.log(result))
        .catch(error => console.log(error));

        });

    });

    return previewFilePromise
  }

  previewFileUsingFilePromise(divId, filePromise, fileName) {
    this.adobeDCView = new window.AdobeDC.View({
      clientId: this.clientId,
      divId,
    })

    this.adobeDCView.previewFile(
      {
        content: {promise: filePromise,},
        metaData: {fileName: fileName,},
      },
      {},
    )
  }

  registerSaveApiHandler() {
    const saveApiHandler = (metaData, content, options) => {
      console.log(metaData, content, options)
      return new Promise((resolve) => {
        setTimeout(() => {
          const response = {
            code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
            data: {
              metaData: Object.assign(metaData, {
                updatedAt: new Date().getTime(),
              }),
            },
          }
          resolve(response)
        }, 2000)
      })
    }

    this.adobeDCView.registerCallback(
      window.AdobeDC.View.Enum.CallbackType.SAVE_API,
      saveApiHandler,
      {},
    )
  }

  registerEventsHandler() {
    this.adobeDCView.registerCallback(
      window.AdobeDC.View.Enum.CallbackType.EVENT_LISTENER,
      (event) => {
        console.log(event)
      },
      {
        enablePDFAnalytics: true,
      },
    )
  }
}

export default ViewSDKClient

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 17, 2022 Feb 17, 2022

Copy link to clipboard

Copied

LATEST

Currently, that's not possible using Embed API. printing must be triggered manually. There is no API to make the viewer print.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources