import 'dart:io';
import 'package:aconvert/pages/view.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:convert';
import 'dart:typed_data';
import 'package:aconvert/services/api.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' as http;
import 'package:pdf_viewer_plugin/pdf_viewer_plugin.dart';
//final clientId = '2720faeb-aa0f-46ee-aa0a-8bf7559268fc';
//final secret = '65cc9d8e63d2a01be5dd5abde8cbc970';
//var configuration = Configuration(secret, clientId);
class Docx extends StatefulWidget {
const Docx({Key? key}) : super(key: key);
@override
_DocxState createState() => _DocxState();
}
class _DocxState extends State<Docx> {
//view pdf
String? docFilePath;
String? docFilename;
String? docFiledata;
File? _file;
late final pathController = TextEditingController();
pick_file() async{
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['doc','txt','TXT','png','jpg','pdf','PDF','rtf'],
);
if (result != null) {
// List<File> files = result.paths.map((path) => File(path!)).toList();
File file = File(result.files.single.path!);
_file = File(result.files.single.path!);
setState(() {
docFilePath =result.files.single.path!;
docFilename = _file?.path.split('/').last;
Uint8List? fileInByte = _file?.readAsBytesSync();
docFiledata = base64Encode(fileInByte!);
print("******** $docFilename **********");
});
} else {
// User canceled the picker
}
}
// convert to pdf api
Future postfile() async{
String url = 'https://v2.convertapi.com/convert/doc/to/pdf?Secret=5Wq3HMYGVzqViAXJ&Token=636106935&StoreFile=true';
final Uri uri = Uri.parse(url);
http.Response response = await http.post(uri,body: {
"Parameters": [
{
"Name": "File",
"FileValue": {
"Name": docFilename,
"Data": docFiledata
}
},
{
"Name": "StoreFile",
"Value": true
}
]
} , headers: {
"Content-Type": "application/json"
});
var responsebody = json.decode(response.body) ;
print('Response status: ${response.statusCode}');
print('------------------------------------');
print('Response body: ${response.body}');
print('------------------------------------');
print('Response body: ${responsebody}');
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('from docx to pdf'),
titleTextStyle: TextStyle(color: Colors.white70 , fontSize: 25 , fontWeight: FontWeight.bold),
backgroundColor: Colors.deepOrangeAccent,
elevation: 0,
centerTitle: true,
),
body: SingleChildScrollView(
child:Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(height: 20,),
InkWell(
onTap: pick_file,
child: Container(
height: 60,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.redAccent,
),
child: Center(child: Text('select file ' ,style: TextStyle(fontSize: 30,color: Colors.white), ))),
),
SizedBox(height: 20,),
InkWell(
onTap: (){
Get.to(()=>View(docFilePath!));
},
child: Container(
height: 60,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.redAccent,
),
child: Center(child: Text('show selected file' ,style: TextStyle(fontSize: 30,color: Colors.white), ))),
),
SizedBox(height: 20,),
//convert
InkWell(
onTap: postfile,
child: Container(
height: 60,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.redAccent,
),
child: Center(child: Text('convert' ,style: TextStyle(fontSize: 30,color: Colors.white), ))),
),
SizedBox(height: 20,),
InkWell(
onTap: (){},
child: Container(
height: 60,
padding: EdgeInsets.all(10),
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.redAccent,
),
child: Center(child: Text('upload to cloud' ,style: TextStyle(fontSize: 30,color: Colors.white), ))),
),
],
),
),
);
}
}
E/flatter(11254):[错误:flatter/lib/ui/ui_dart_state.cc(209)]未处理的异常:错误状态:无法设置属性类型为“application/json”的请求的正文字段。E/颤振(11254):#0请求。bodyFields=(包:http/src/request.dart:133:7)E/flatter(11254):#1 BaseClient_sendUnstreamed(包:http/src/base_client.dart:87:17)E/flatter(11254):#2 BaseClient。post(包:http/src/base_client.dart:32:7)E/flatter(11254):#3 post。(软件包:http/http.dart:69:16)E/flatter(11254):#4_withClient(软件包:http/http.dart:164:20)E/flutter(11254):第5篇文章。postfile(包:aconvert/pages/fromdocxtopdf.dart:61:40)E/flatter(11254):#7_InkResponseState_handleTap(包:颤振/src/材料/墨水井。省道:989:21)E/颤振(11254):#8手势识别器。调用调用回调(包:flatter/src/gestures/recognizer.dart:198:24)E/flatter(11254):#9 TapgestureRecogizer。handleTapUp(软件包:flatter/src/signatures/tap.dart:608:11)E/flatter(11254):#10基本姿势识别器_检查(包:颤振/src/手势/轻拍。省道:296:5)E/颤振(11254):#11基本姿势识别器。handlePrimaryPointer(包:flatter/src/手势/轻拍。省道:230:7)E/flatter(11254):#12初级指针检测识别器。handleEvent(软件包:颤振/src/手势/识别器。dart:563:9)E/颤振(11254):#13指针输出器_调度(包:flatter/src/signatures/pointer_router.dart:94:12)E/flatter(11254):#14 PointerRouter._dispatchEventToRoutes。(软件包:flatter/src/signatures/pointer_router.dart:139:9)E/flatter(11254):#15_LinkedHashMapMixin。forEach(省道:收集补丁/压缩散列。省道:539:8)E/flatter(11254):#16点路由器_dispatchEventToRoutes(包:flatter/src/手势/指针路由器。dart:137:18)E/flatter(11254):#17指针路由器。路线(包:颤振/src/手势/指针_router.dart:123:7)E/颤振(11254):#18手势绑定。handleEvent(包:颤振/src/手势/绑定。dart:439:19)E/颤振(11254):#19手势绑定。dispatchEvent(包:flatter/src/手势/绑定。dart:419:22)E/flatter(11254):#20渲染器绑定。调度事件(包:flatter/src/rendering/binding.dart:322:11)E/flatter(11254):#21手势绑定_立即用手点(包:颤振/src/手势/绑定。省道:374:7)E/颤振(11254):#22手势绑定。HandlePointeEvent(包:颤振/src/手势/绑定。dart:338:5)E/颤振(11254):#23手势绑定_flushPointerEventQueue(包:flutter/src/手势/绑定。省道:296:7)E/flutter(11254):#24手势绑定_handlePointerDataPacket(包:flatter/src/手势/绑定。dart:279:7)E/flatter(11254):#25_rootRunUnary(dart:async/zone.dart:1442:13)E/flutter(11254):26_CustomZone。RUNUARY(省道:异步/区域。省道:1335:19)E/颤振(11254):#27_CustomZone。runUnaryGuarded(dart:async/zone.dart:1244:7)E/flutter(11254):#28_invoke1(dart:ui/hooks.dart:170:10)E/Flatter(112 54):35; 29 PlatformDispatcher_dispatchPointerDataPacket(dart:ui/platform_dispatcher.dart:331:7)E/Flatter(11254):#30_DisPATchPointerData Packet
您需要用jsonEncode()包装主体
final body = {
"Parameters": [
{
"Name": "File",
"FileValue": {
"Name": docFilename,
"Data": docFiledata
}
},
{
"Name": "StoreFile",
"Value": true
}
]
};
http.Response response = await http.post(
uri,
body: jsonEncode(body),
headers: {"Content-Type": "application/json"}
);
问题内容: 如何使用Java将pdf文件转换为word文件? 而且,它看起来像它一样容易吗? 问题答案: 试试PDFBOX
我需要使用python将.doc和.docx文件转换为.pdf。我已经看到了一些可用的答案,但它们使用的是comtypes和OpenWordApplication。我不能那样做。我寻求的是一种使用一些python库的方法,这些库保留字体、表格、标题大小和图像等,而不打开MS Word或LibreOffice或类似的东西,如果需要的话,将.doc和.docx文件转换为某种中间格式(然后将该格式转换为
本文向大家介绍php使用Image Magick将PDF文件转换为JPG文件的方法,包括了php使用Image Magick将PDF文件转换为JPG文件的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了php使用Image Magick将PDF文件转换为JPG文件的方法。分享给大家供大家参考。具体如下: 这是一个非常简单的格式转换代码,可以把.PDF文件转换为.JPG文件,代码要起作用
我在java中创建了一个在桌面上执行时可以正常工作的Swing游戏。但是,由于不可预见的事件,我的老板现在要求将游戏变成一个小程序,以便可以嵌入到网站中(不,JWS不是一个选项)。 以下是我将游戏转换为小程序的步骤: 1)将我的main类更改为具有public ulureinit()而不是public静态ululemain(),并从Applet扩展它 2) 更改了我的myJFrame。java类现
本文向大家介绍Asp.net中将Word文件转换成HTML的方法,包括了Asp.net中将Word文件转换成HTML的方法的使用技巧和注意事项,需要的朋友参考一下 本文所述为一个Asp.net实现将Word转换为HTML的功能,其关键代码如下: 上述代码,在.net framework4.0 中,可能会出一编译错误,如下所示: 无法嵌入互操作类型“……”,请改用适用的接口。 经过查阅资料,找到解决
我的程序是采取任何类型的文件和打开他们自己。 我已经试过了 我只使用文件获得正确的数据。