question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is binary supported?

See original GitHub issue

We have an API endpoint that returns us the binary file ('content-type': 'binary/octet-stream') of a PDF. However, when I pass the blob response to the component, several different errors are displayed on the developer’s console:

Error: Invalid XRef stream header
pdf.worker.js:355     at error (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:1256:17)
    at XRef_readXRef [as readXRef] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:22222:29)
    at XRef_parse [as parse] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:21892:28)
    at PDFDocument_setup [as setup] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:30797:17)
    at PDFDocument_parse [as parse] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:30686:12)
    at http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:40459:28
    at Promise (<anonymous>)
    at LocalPdfManager_ensure [as ensure] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:40454:14)
    at LocalPdfManager.BasePdfManager_ensureDoc [as ensureDoc] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:40406:19)

pdf.worker.js:346 Warning: Indexing all PDF objects

pdf.worker.js:354 Error: Bad FCHECK in flate stream: 120, 253
pdf.worker.js:355     at error (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:1256:17)
    at FlateStream (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:2870:23)
    at Parser_makeFilter [as makeFilter] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:5734:18)
    at Parser_filter [as filter] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:5701:21)
    at Parser_makeStream [as makeStream] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:5690:21)
    at Parser_getObj [as getObj] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:5358:47)
    at XRef_fetchUncompressed [as fetchUncompressed] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:22309:28)
    at XRef_fetch [as fetch] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:22272:26)
    at XRef_fetchIfRef [as fetchIfRef] (http://localhost:3030/_nuxt/7f662a37670c93fa585a.worker.js:22255:19)

pdf.worker.js:346 Warning: Invalid stream: "Error: Bad FCHECK in flate stream: 120, 253"

The template is very simple:

<template>
  <pdf v-bind:src="report" />
</template>

<script>
  import axios from 'axios';
  import pdf from 'vue-pdf';

  const api = axios.create({
    baseURL: `https://api.ourdomain.com/v1`,
    responseType: 'blob'
  });

  export default {
    components: {
      pdf
    },
    async asyncData(ctx) {
      const {params: {id}, query: {uid, rid}} = ctx;

      let url = `/report/${id}`;
      const params = {
        media: 'pdf',
        uid, rid
      };

      const blob = await api.get(url, {params}).then(response => {
        return {data: response.data};
      });

      return {
        report: blob
      }
    }
  }
</script>

Pretty sure I’m missing something.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
FranckFreiburgercommented, Jan 4, 2018

@betacar here is a complete example:

<template>
  <pdf :src="pdfSrc"></pdf>
</template>

<script>
import vuePdf from 'vue-pdf'

// since vue-pdf may be used server-side (see vuejs ssr)
// converts base64 string into binary data as a javascript string
var base64ToString = process.env.VUE_ENV === 'server' ? function(base64) { return Buffer.from(base64, 'base64').toString() } : window.atob;

// get the binary version of the pdf
var binaryVersionOfThePdf = base64ToString('JVBERi0xLjUKJbXtrvsKMyAwIG9iago8PCAvTGVuZ3RoIDQgMCBSCiAgIC9GaWx0ZXIgL0ZsYXRlRGVjb2RlCj4+CnN0cmVhbQp4nE2NuwoCQQxF+/mK+wMbk5lkHl+wIFislmIhPhYEi10Lf9/MVgZCAufmZAkMppJ6+ZLUuFWsM3ZXxvzpFNaMYjEriqpCtbZSBOsDzw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AwMDAwNjQ1IDAwMDAwIG4gCjAwMDAwMDA3NzIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSA4CiAgIC9Sb290IDcgMCBSCiAgIC9JbmZvIDYgMCBSCj4+CnN0YXJ0eHJlZgo4MjQKJSVFT0YK');

export default {
	components: {
		'pdf': vuePdf,
	},
	data() {
		return {
			// since vue-pdf use PDFJS.getDocument(), we can do:
			pdfSrc: { data: binaryVersionOfThePdf }
		}
	}
}
</script>
1reaction
FranckFreiburgercommented, Jan 5, 2018

v3.0.1 is the latest version available on npm

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binary-code compatibility - Wikipedia
Binary-code compatibility (binary compatible or object-code-compatible) is a property of a computer system, meaning that it can run the same executable code ...
Read more >
Binary Compatibility - Computerworld
Two computers can be considered binary compatible if they can run the same software without requiring that the application be recompiled. The computers...
Read more >
What is binary compatibility in Java? - Stack Overflow
In short, binary compatibility means that when you change your class, you do not need to recompile classes that use it. For example,...
Read more >
Binary Compatibility for Linux Distributions | tuxcare.com
Two distinct computing environments are binary compatible if source ... CentOS and Oracle Linux are application binary compatible with RHEL.
Read more >
What is a binary file and how does it work? - TechTarget
A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found