Giter VIP home page Giter VIP logo

nguyenlequocdat04 / webcontent_converter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kechankrisna/webcontent_converter

0.0 0.0 0.0 6.79 MB

This plugin was made for developer to convert any webcontent, web uri to image bitmap or pdf file. This plugin use WebView on android, WKWebView on Ios and chromium for desktop support.

License: GNU Affero General Public License v3.0

Ruby 1.11% C++ 6.89% C 0.44% Objective-C 0.24% Kotlin 6.24% Dart 52.70% Swift 4.84% HTML 22.59% CMake 4.94%

webcontent_converter's Introduction

webcontent_converter

This plugin was made for developer to convert any webcontent, web uri to image bitmap or pdf file. This plugin use WebView on android, WKWebView on Ios and chromium for desktop support. This plugin was test for android, ios and desktop.

Support :

  • ✓ Android Minimum SDK Version: 21
  • ✓ IOS minimum target Version: 11
  • ✓ Deskop linux, windows, macos
Android IOS Desktop
WebView WkWebView Puppeteer

Methods

CONVERT TO IMAGE

  • filePathToImage(String path, double duration) : path is asset path and duration is delay time. This function will return Uint8List Image

Example:

var bytes = await WebcontentConverter.filePathToImage(path: "assets/receipt.html");
if (bytes.length > 0) _saveFile(bytes);
  • webUriToImage(String uri, double duration) : uri is web uri(url) and duration is delay time. This function will return Uint8List Image

Example:

var bytes = await WebcontentConverter.webUriToImage(
uri: "http://127.0.0.1:5500/example/assets/receipt.html");
if (bytes.length > 0) _saveFile(bytes);
  • contentToImage(String content, double duration) : content is html or web content and duration is delay time. This function will return Uint8List Image

Example:

final content = Demo.getReceiptContent();
var bytes = await WebcontentConverter.contentToImage(content: content);
if (bytes.length > 0) _saveFile(bytes);

*** Purpose: The three above functions will help developer to get screenshot of html content as Uint8List Image and push it to esc printer

Receipt screenshot

CONVERT TO PDF

  • filePathToPdf(String path, double duration, String savedPath, PdfMargins margins, PaperFormat format )

Example:

var dir = await getApplicationDocumentsDirectory();
var savedPath = join(dir.path, "sample.pdf");
var result = await WebcontentConverter.filePathToPdf(
    path: "assets/invoice.html",
    savedPath: savedPath,
    format: PaperFormat.a4,
    margins: PdfMargins.px(top: 35, bottom: 35, right: 35, left: 35),
);
  • webUriToPdf(String uri, double duration, String savedPath, PdfMargins margins, PaperFormat format )

Example:

var dir = await getApplicationDocumentsDirectory();
var savedPath = join(dir.path, "sample.pdf");
var result = await WebcontentConverter.webUriToPdf(
    uri: "http://127.0.0.1:5500/example/assets/invoice.html",
    savedPath: savedPath,
    format: PaperFormat.a4,
    margins: PdfMargins.px(top: 35, bottom: 35, right: 35, left: 35),
);
  • contentToPDF(String content, double duration, String savedPath, PdfMargins margins, PaperFormat format )

Example:

final content = Demo.getInvoiceContent();
var dir = await getApplicationDocumentsDirectory();
var savedPath = join(dir.path, "sample.pdf");
var result = await WebcontentConverter.contentToPDF(
    content: content,
    savedPath: savedPath,
    format: PaperFormat.a4,
    margins: PdfMargins.px(top: 55, bottom: 55, right: 55, left: 55),
);

*** Purpose: The three above functions will help developer to get pdf printed file of html content as. It will return a savedPath when saved successful otherwise null

Desktop top

    flutter pub run webcontent_converter:install_desktop download

This cli will download the chrome version base on your current operating system and save into path assets/.local-chromium/ directory as a zip file

    flutter pub run webcontent_converter:install_desktop extract

This cli will extract the chrome zip file based on your current operating system and save into path assets/.local-chromium/ directory

add this code into your flutter app will help you to ship chromium zip in asset directory into production build for desktop deployment

var executablePath = await ChromeDesktopDirectoryHelper.saveChromeFromAssetToApp();
WebViewHelper.customBrowserPath = [executablePath];
await WebcontentConverter.ensureInitialized(executablePath: executablePath);

Invoice screenshot

webcontent_converter's People

Contributors

kechankrisna avatar subairlithos avatar renanzdm avatar sbrsubuvga avatar a7mdlbanna avatar sudhanshukumaryadav avatar nguyenlequocdat04 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.