How to convert PDF file to DOC file in Flutter Web? - flutter

I am creating pdf file from pdf package in pub.dev, now I want to convert that pdf file to doc file so how to convert pdf to doc in flutter web?

https://pub.flutter-io.cn/packages/docx_template
Use this package if you wish to editthe doc file.
When you save the pdf you must be using
await pdf.save();
This will return a bytes array add that to the doc file like
final of = File('generated.docx');
await of.writeAsBytes(await pdf.save());

Related

How to load pdf file from directory using PdfDocument.load using pdf package in flutter desktop

I am able to read the file as byte
final bytes = File("path....").readAsBytesSync();
//now, here is the problem
final doc = PdfDocument.load(parserBase);
★ that abstract class PdfDocumentParserBase(bytes) takes Uint8list as its argument which is also a parameter for
PdfDocument.load(parserBase)
, am not good at abstract classes and don't know how to use it in the method.
What I want to achieve is merging multiple pdf files.
Please help me out.
Thanks

Convert base64 String into PDF file in Flutter

I am trying to show a PDF file. But PDF file I am receiving from server in Base64 String format. Is there any way I can directly show Base64 String into PDF viewer or WebView without saving it into File.
Check this : https://stackoverflow.com/a/55599926/305135
(Following code is copied from link above)
This should convert base64 encoded pdf data into a byte array.
import 'packages:dart/convert.dart';
List<int> pdfDataBytes = base64.decode(pdfBase64)
.map((number) => int.parse(number));
The pdf and the image plugins seems to suit your needs for displaying pdf.
The code should be roughly like so:
import 'package:pdf/pdf.dart';
import 'package:image/image.dart';
...
Image img = decodeImage(pdfDataBytes);
PdfImage image = PdfImage(
pdf,
image: img.data.buffer.asUint8List(),
width: img.width,
height: img.height);
// Display it somehow
...
At first i was doing the same thing like you. But i didnt file any appropriate solution to convert the base64 String into a pdf file.
I think you can get the BufferArray and then convert it into a pdf file.
I have answered how to parse blob data to pdf in this question :
How to convert ByteBuffer to pdf

Flutter: How to get a File object from ImageProvider in Flutter?

How can I get a File from an ImageProvider?
ImageProvider imageProvider = NetworkImage(networkUrl);
File file = imageProvider ?
Although ImageProvider with NetworkImage renders the content of your network image URL, it doesn't have direct APIs or easy way for you to be able to convert it to a File object. With that said, you can still manually cache (or download) the image/s and get the download stream.
As far as I can understand your question, you are trying to access the network image URL as a File object. Instead of using ImageProvider, you can take a look at the flutter_cache_manager, which is a plugin used for downloading and caching files locally, and save it for later use.
Example Usage
Downloading network image file from URL
await DefaultCacheManager().downloadFile(url);
Retrieving File object from the cache dir
// Retrieving File object
var file = await DefaultCacheManager().getSingleFile(imageUrl);
// File object available for use
// Eg. Reading file as string
file.readAsStringSync(...);
Further reading
https://pub.dev/packages/flutter_cache_manager
https://pub.dev/packages/cached_network_image

C# Generated PDF File Does not save

I have created a pdf file using c# code and now i want to save created pdf file into my local machine drive "E" but an error shown to me that "Access to the path 'E:\My Projects' is denied."...
here is the code to save pdf file
FileStream fileStream = new FileStream(#"E:\My Projects", FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.None);
Any one please help me out....
Assuming you have
path a string with the full qualified name and
pdf a byte[] of the generated pdf,
then just do:
File.WriteAllBytes(path, pdf);
See http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes.aspx

iText: Insert pdf bytes into an opened document

Currently, our team is using Image.getInstance(bytes[]) to get an image object from png bytes. But later we will use a pdf file instead of png. So my question is that given pdf bytes, is there any way to convert it into png bytes or insert into opened document?
Something like this:
void insertIntoDocument(byte[] pdfBytes, Document document){}