Display PDF or PPT files in the Flutter App - flutter

I want to show my PDF and PPT files within the app without using any other app in Flutter.
Not from the local assets but from web Urls.

For PDF you can use this package: https://pub.dev/packages/advance_pdf_viewer
Example:
Load from URL
PDFDocument doc = await PDFDocument.fromURL(yourURL);
Container(
child: PDFViewer(document: doc)),
);

Related

Open PDF In PDF Viewer

I have a PDF in the assets folder: assets/my_resume.pdf.
How can I open it in a PDF viewer? I don't want to open it in a widget. I want it to open outside of my app with whatever PDF viewer is available to this device.
I tried: https://pub.dev/packages/open_file but that doesn't work with assets.
Future<void> launchPdf() async {
}
How can I do this? I mostly care about mobile so not even considering web.
I don't know if this is the best method, but you could load the pdf file data, and save it to, for example, the Document directory on the device, and after that, use the open file package to open the pdf with a native device app.
void openAsset() async {
// load pdf into ram
ByteData pdf = await DefaultAssetBundle.of(context).load('assets/your_pdf.pdf');
// get documents directory
Directory documents = await getApplicationDocumentsDirectory();
// write data to a file in the documents directory
await File(documents.path + '/your_pdf.pdf').writeAsBytes(pdf.buffer.asUint8List());
// call open_pdf function
// ...
}
(Didn't test the code)

Flutter Web deployed - How to display a pdf file in a new tab from assets folder

As the title suggests, I can't open a .pdf file from my project's assets folder in a new browser tab. This thing happens to me only in the deployed version of my web app, locally it works.
Thi is the part of the code that I need to work:
TextButton(
onPressed: () async {
var bytes = await rootBundle.load("assets/files/test.pdf"); // location of your asset file
final blob = html.Blob([bytes], 'application/pdf');
final url = html.Url.createObjectUrlFromBlob(blob);
html.window.open(url, "_blank");
html.Url.revokeObjectUrl(url);
},
child: Text(
"OPEN PDF.",
style: AppTextStyles.DIALOG_CONTENT_TEXT_STYLE.copyWith(fontSize: 11),
))
Simply, by clicking on the text I want to open the pdf file saved in the assets folder in a new tab. I have already entered the path of the assets folder inside pubspec.yaml.
Can anyone help me? I have found various solutions that work for Android and IOS, but unfortunately not for the web...

Adding button in pdf made using pdf package in flutter

I am using the pdf package in flutter for generating pdf from the app. I need to add a clickable kind of thing(hyperlink, button) in pdf but the package doesn't provide any widget for that purpose. Also, the basic flutter widgets couldn't be used for generating the pdf files(restricted by the package). Is there any way to solve it?
Use the Stack widget to put any widget above the pdf ?
The problem is solved now, the pdf package provides the UrlLink for the purpose of opening a link when tapped on the page.
This is the short documentation for the same.
I did it like this-
pw.UrlLink(destination: imageUrl, child: pw.Text('LINK', style: pw.TextStyle(fontSize: size)))

Flutter web doesn't recognise pdf file format

I'm trying to show the pdf file when pushing the button but no success so far. Can there be the reason that the format of the pdf file has that question mark on the icon meaning the framework doesn't recognise the format?
No, the Assets folder can contain any file regardless of the file extension. Have you define your assets folder in pubspec.yaml like this?
assets:
- assets/pdf/
If yes you can use native_pdf_view library as it supports asset loading as well as full screen. You should be able to implement it as follows:
final pdfController = PdfController(
document: PdfDocument.openAsset('assets/copy.pdf'),
);
return Scaffold(
body: Center(
child: PdfView(
controller: pdfController,
)
),
);
Original link to the post is here.

Flutter : How to block full screen video in webview?

I use "webview_flutter: ^1.0.7" plugin in my flutter app to open a webview but I have a problem when a website launch a video after a click anywhere on the screen an it's open in fullscreen. How to disable it without disable javascript ? I want to play the video but not in fullscreen
I can't use "AutoMediaPlaybackPolicy" because there is an action
One way would be to update html file:
String hmtlCode = (await http.get(initialUrl)).body;
# edit this code (either append to string, or find and replace)
https://itqna.net/questions/80033/how-disable-full-screen-html5-video-any-browser (html example how to disable full screen)
and then feed this html to webview
String hmtlCode = ....;
String url = Uri.dataFromString(hmtlCode, mimeType: 'text/html', encoding: Encoding.getByName('utf-8')).toString();
WebView(
initialUrl: url,
...