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

How to add <img> html tag with local image in RN project folder? #302

Open
Lucas-Perazzo opened this issue Aug 23, 2023 · 6 comments
Open

Comments

@Lucas-Perazzo
Copy link

I am creating a pdf and I need to use an image that I have saved in my project.
I use the img tag but it doesn't show anything, the only solution I found is to use a

with a background image but only if it is a url not with local images. Can you help me?

@MTPL0005-AbhishekDube
Copy link

Have you got any solution ?

@jeroen-van-dijk
Copy link

I managed to get custom fonts and images working by using base64 formatted assets

@Aswin-Inigo
Copy link

Any one has any idea to resolve this issue?

@WilliamOchy
Copy link

WilliamOchy commented Aug 30, 2024

just do something like this

<img src="${ Image.resolveAssetSource( require('assets/images/apple.png'), ).uri }" />

and import Image from react-native
import {Image} from 'react-native';

@bumpingChris
Copy link

@Lucas-Perazzo @WilliamOchy Hi, Do you know how to get images in local Documents directory to show?

@bumpingChris
Copy link

bumpingChris commented Oct 22, 2024

I am able to get images stored in the local Documents directory on iOS to show by changing the following code in the RNHTLtoPDF.m file (lines 174-184) and writing the HTML string to a file called "html2pdf.html" saved to the Documents/htmlDirectory/ folder:


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSURL *baseURL = [NSURL fileURLWithPath:documentsDirectory];
    NSURL *baseURL2 = [baseURL URLByAppendingPathComponent: @"htmlDirectory"];
    NSURL *baseURL3 = [baseURL2 URLByAppendingPathComponent: @"html2pdf.html"];
 
    dispatch_async(dispatch_get_main_queue(), ^{
        [_webView loadFileURL:baseURL3 allowingReadAccessToURL:baseURL];
    });

If someone can show how this could be done in Android as well....

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

6 participants