你好,所以我用这个包来显示PDF在我的应用程序pub.dev/packages/flutter_full_pdf_viewer和PDF包pub.dev/packages/pdf创建PDF。
这是我用来创建PDF并导航到PDF查看器页面的代码:
Future<Uint8List> generateInvoice(
PdfPageFormat pageFormat, SalesOrder salesOrder) async {
final lorem = pw.LoremText();
final invoice = Invoice(
salesOrder: salesOrder,
orders: salesOrder.listOrder.where((e)=>e.status==0).toList(),
paymentInfo:
'4509 Wiseman Street\nKnoxville, Tennessee(TN), 37929\n865-372-0425',
baseColor: PdfColors.blueGrey800,
accentColor: PdfColors.blueAccent700,
);
return await invoice.buildPdf(pageFormat);
}
createInvoice(SalesOrder salesOrder) async {
var a = await DownloadsPathProvider.downloadsDirectory;
print("path = "+a.path);
final String dir = "/storage/emulated/0/Download";
final String path = '$dir/example.pdf';
final File file = File(path);
Uint8List invoice = await ig.generateInvoice(PdfPageFormat.a4, salesOrder);
await file.writeAsBytes(invoice);
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => PdfScreen(path: path)));
}
这是我的PDF浏览器屏幕
class PdfScreen extends StatelessWidget {
final String path;
PdfScreen({this.path});
@override
Widget build(BuildContext context) {
print(path);
return PDFViewerScaffold(path: path);
}
}
这是我的build gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
applicationId "com.example.test"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
signingConfig signingConfigs.debug
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
ndk {
abiFilters 'armeabi-v7a'
}
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}
它有时工作正常,但经过大量的应用程序中的变化,每当我打开PDF查看器屏幕总是变成白色,这个错误出现:
E/com.shockwave.pdfium.PdfiumCore(32664): Native libraries failed to load - java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-2/lib/arm64, /data/app/com.example.test-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libmodpng.so"
E/art (32664): No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)
E/PDFView (32664): load pdf error
E/PDFView (32664): java.lang.UnsatisfiedLinkError: No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)
非常感谢
1条答案
按热度按时间2uluyalo1#
我不知道为什么会发生这种情况,但我通过清理Flutter项目来解决它。谢谢