Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hey i am getting this error "Warning: fetchStandardFontData: failed to fetch file "LiberationSans-Bold.ttf" is there way how i can fix this?? #1

Closed
sujjeee opened this issue Feb 8, 2024 · 6 comments

Comments

@sujjeee
Copy link

sujjeee commented Feb 8, 2024

Hey there,

I noticed your previous conversations regarding this issue, so I thought I'd ask if you could help me with it. Basically, I'm encountering this error and I don't know how to fix it:

Warning: fetchStandardFontData: failed to fetch file "LiberationSans-Regular.ttf" with "UnknownErrorException: The standard font "baseUrl" parameter must be specified, ensure that the "standardFontDataUrl" API parameter is provided.".

Please help me if you know how to deal with this.

@Luluno01
Copy link
Owner

Luluno01 commented Feb 8, 2024

I haven't been tackling PDF.js for a while but I do remember there is such a warning. I didn't fix it because it's a warning and I don't use PDF.js to render anything. If you don't really need to render the PDF, you can ignore this warning, too. But if you need to, the warning message indicates that you have to specify a parameter which tells PDF.js where "standard fonts" are, as explained by react-pdf.

Here is another issue under PDF.js for your reference: mozilla/pdf.js#4244

@sujjeee
Copy link
Author

sujjeee commented Feb 8, 2024

Thanks for the reply!!

By the way, I tried to provide the path for the standard font, but I'm still encountering the same error. My terminal is filled with the same error message.

This is how I'm providing the path:

const pdf = await getDocument({
  data: uint8Array,
  standardFontDataUrl:
    "{....}/node_modules/pdfjs-dist/standard_fonts"
}).promise;

However, I still don't know why I'm getting the error.

@Luluno01
Copy link
Owner

Luluno01 commented Feb 8, 2024

Thanks for the reply!!

By the way, I tried to provide the path for the standard font, but I'm still encountering the same error. My terminal is filled with the same error message.

This is how I'm providing the path:

const pdf = await getDocument({
  data: uint8Array,
  standardFontDataUrl:
    "{....}/node_modules/pdfjs-dist/standard_fonts"
}).promise;

However, I still don't know why I'm getting the error.

The error message should be a bit different after you provide standardFontDataUrl. Could you post the error message you got after setting standardFontDataUrl?

Also, if you plan to run PDF.js in a browser, you need to fill in standardFontDataUrl with the base URL where standard_fonts can be fetched by an HTTP request sent from the browser. For example, you can firstly make sure standard_fonts/* are served as static assets. You can achieve this by copying standard_fonts folder to the assets folder. Then, set standardFontDataUrl to '/standard_fonts' (which points to the assets/standard_fonts folder). It should, hopefully, be used to construct full URLs to the fonts that are served from your static assets folder.

Otherwise, if you plan to run PDF.js in serverless function, you probably need to figure out how to make Webpack copy the entire standard_fonts folder to the build output so that standardFontDataUrl points to a folder that actually exists at runtime. The precise configuration, unfortunately, is not known to me as I'm not familiar with Webpack stuff (it's annoying, huh? XD). So, you may need to search through the documentations of both Next.js and Webpack. Make sure you are looking into the right version of documentation that matches the Webpack version you are using. You can also open an issue in the PDF.js repo or Next.js repo to seek for more help.

@sujjeee
Copy link
Author

sujjeee commented Feb 9, 2024

Okay, so I'm using pdfjs-dist in Node.js to obtain the dimensions of the given text and perform some actions on it. In simple terms, I need to extract the text from each page of the PDF.

import { getDocument } from "pdfjs-dist";

const uint8Array = new Uint8Array(response);

const pdf = await getDocument({
  data: uint8Array,
  standardFontDataUrl:
    "D:/PDFScribe/nodejs/node_modules/pdfjs-dist/standard_fonts"
}).promise;

And speaking about my terminal being filled with warnings, I mean it! Look at this image XD.
Screenshot 2024-02-09 114836

The code is working fine, it's just this warning that's annoying me a lot!

@Luluno01
Copy link
Owner

Luluno01 commented Feb 9, 2024

Okay, so I'm using pdfjs-dist in Node.js to obtain the dimensions of the given text and perform some actions on it. In simple terms, I need to extract the text from each page of the PDF.

import { getDocument } from "pdfjs-dist";

const uint8Array = new Uint8Array(response);

const pdf = await getDocument({
  data: uint8Array,
  standardFontDataUrl:
    "D:/PDFScribe/nodejs/node_modules/pdfjs-dist/standard_fonts"
}).promise;

And speaking about my terminal being filled with warnings, I mean it! Look at this image XD. Screenshot 2024-02-09 114836

The code is working fine, it's just this warning that's annoying me a lot!

End standardFontDataUrl with a trailing slash and it should fix it. Notice that in the warning message, the paths where PDF.js wants to load fonts from are constructed from standardFontDataUrl directly without adding a slash.

@sujjeee
Copy link
Author

sujjeee commented Feb 9, 2024

@Luluno01 Reallyyy, thank you so much, man!!

I was just so frustrated with that warning, and the issue was just this --> '/ '
Thanks again for helping; it's fixed now.

@Luluno01 Luluno01 closed this as completed Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants