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.

cann't save image tag with base64

See original GitHub issue

I trying with imgage tag but not working My code: let options = { html: <h1>Image</h1> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAACUCAYAAAB1PADUAAAAAklEQVR4AewaftIAAAT1SURBVO3BQY4kRxLAQDJQ//8yd45+SiBR0S2N1s3sD9a65LDWRYe1LjqsddFhrYsOa110WOuiw1oXHda66LDWRYe1LjqsddFhrYsOa110WOuiw1oXffiSym+qmFSeVEwqU8Wk8kbFpDJVfEPlN1V847DWRYe1LjqsddGHyypuUnmjYlKZKp5UTCpTxRsqb1Q8qbhJ5abDWhcd1rrosNZFH36YyhsVb1RMKlPFTSpTxVQxqfwklTcqftJhrYsOa110WOuiD385lScqTyomlaliUplUpoqp4onKf8lhrYsOa110WOuiD3+5iknlScUbKk8qJpWpYlL5LzusddFhrYsOa1304YdV/JMq3qh4Q+WJylQxqXyj4t/ksNZFh7UuOqx10YfLVH6TylQxqUwVk8pUMalMFU8qJpWbVP7NDmtddFjrosNaF9kf/MVUvlFxk8pU8URlqvibHda66LDWRYe1LvrwJZWpYlJ5UjGpvFHxDZWbKp6oTBVPVKaKJypTxaTypOIbh7UuOqx10WGtiz58qWJSeVIxqUwVb6hMFZPKVPFGxRsqU8VU8URlqnii8m9yWOuiw1oXHda66MNlFZPKpDJVPFGZKt6oeKNiUpkq3lCZKp5UPFGZKv5NDmtddFjrosNaF334YRXfqJhU3lB5Q2Wq+EbFpPKk4g2VNyomlZsOa110WOuiw1oXffiSylTxROWmiknlScVNKlPFGxWTylTxRsWk8qTipsNaFx3Wuuiw1kX2Bxep3FTxRGWqmFSeVEwqb1RMKlPFpPKNikllqniiMlXcdFjrosNaFx3WuujDZRWTylTxRGVSmSq+UTGpTBWTylTxpOIbFU9Unqi8oTJVfOOw1kWHtS46rHWR/cEvUnmj4jepTBWTypOKSWWqmFSmiknlpopJZar4xmGtiw5rXXRY66IPv6xiUnmiMlVMKlPFpDJVPKl4UjGpPKmYVKaKSWWqmFSmiknln3RY66LDWhcd1rrI/uAvpvKk4onKk4pJZar4hspU8UTlScWk8qTipsNaFx3Wuuiw1kUfvqQyVUwqTyqeqDypmFS+UfGkYlJ5o2KqmFRuqphUJpWp4huHtS46rHXRYa2L7A9+kcobFU9UpopJZaq4SeVJxaTyRsUbKm9U3HRY66LDWhcd1rrow2UqU8U3VN5QeaLyRsUbFZPKVDGpPFF5o2JS+U2HtS46rHXRYa2L7A/+YipTxaQyVUwqb1RMKlPFGypTxRsqU8UTlScV3zisddFhrYsOa1304Usqv6niicpUMalMFZPKVPGk4g2VN1SmiicqU8VU8ZMOa110WOuiw1oXfbis4iaVNyqeVEwqU8U3VKaKb1S8UfGGylTxjcNaFx3Wuuiw1kUffpjKGxVvVEwqU8Wk8obKVPGGylQxqUwqf7PDWhcd1rrosNZFH/5yKlPFb1L5RsWkMlV8Q+VJxU2HtS46rHXRYa2LPvyfqXiiMlVMKjepTBWTyhsVU8UTlaniG4e1LjqsddFhrYs+/LCKn1QxqXyj4knFpDJVTCqTyhsVk8oTlaliUvlJh7UuOqx10WGtiz5cpvKbVKaKSWWqeKIyVUwqb1S8oTJVPKmYVJ5U/KTDWhcd1rrosNZF9gdrXXJY66LDWhcd1rrosNZFh7UuOqx10WGtiw5rXXRY66LDWhcd1rrosNZFh7UuOqx10WGti/4HR6phKbnXrx0AAAAASUVORK5CYII=" width="200" height="200" /> , fileName: saveFile, directory: ‘docs’, }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

1reaction
esuttoncommented, Feb 2, 2018

This fixes base64 images for Android.

File: RNHTMLtoPDFModule.java

  private String convertToPDF(String htmlString, File file) throws Exception {
    try {
      // Rectangle one = new Rectangle(70,140);
      // Rectangle two = new Rectangle(700,400);
      // document.setPageSize(one);
      // Rectangle pageSizeUsLetterPortrait = new Rectangle(612, 861);
      Rectangle pageSizeUsLetterLandscape = new Rectangle(861, 612);

      // Todo: Make a page size option or create rectangle passed in by options
      // A4 is European letter size 8.3 x 11.7 in
      // Document document = new Document();
      // Document document = new Document(PageSize.A4.rotate());
      // https://developers.itextpdf.com/examples/itext5-building-blocks/page-size
      Document document = new Document(pageSizeUsLetterLandscape);

      PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file));

      FontFactory.setFontImp(fontProvider);
      for (String font : customFonts) {
        fontProvider.register(font);
      }

      document.open();
      document.add(new Chunk("")); // This prevent empty document exception

      CSSResolver cssResolver =
              XMLWorkerHelper.getInstance().getDefaultCssResolver(true);

      HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
      htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
      htmlContext.setImageProvider(new Base64ImageProvider());   
      
      PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, pdfWriter);
      HtmlPipeline html = new HtmlPipeline(htmlContext, pdfWriterPipeline);
      CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);

      XMLWorker xmlWorker = new XMLWorker(css, true);
      XMLParser xmlParser = new XMLParser(xmlWorker);
      xmlParser.parse(new ByteArrayInputStream(htmlString.getBytes()));
      document.close();

      String absolutePath = file.getAbsolutePath();
      return absolutePath;
    } catch (Exception e) {
      throw new Exception(e);
    }
  }
0reactions
stale[bot]commented, Dec 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to save a PNG image server-side, from a base64 data URI
Save this answer. Show activity on this post. You need to extract the base64 image data from that string, decode it and then...
Read more >
Saving An Image As Base64 - Talking HighTech
In the post, we will try to save some valuable time by converting the image to a string using the base64 encoding technique....
Read more >
How to Display Base64 Images in HTML - W3docs
Images encoded with Base64 can be embedded in HTML by using the <img> tag. This can help to increase the page load time...
Read more >
2.6 Saving Images and Base64 Encoding - YouTube
Your browser can't play this video. ... 2.6 Saving Images and Base64 Encoding - Working with Data and APIs in JavaScript.
Read more >
How to upload files from your HTML form using Base64 ...
We can't just send the Base64 string to our server and process it, what makes it ... <img src="data:image/jpeg;base64 ... npm i --save...
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