适用于Linux桌面的Flutter PDF Viewer [英] Flutter PDF Viewer for Linux desktop

查看:99
本文介绍了适用于Linux桌面的Flutter PDF Viewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Flutter上为Android和Linux桌面平台开发了一种具有PDF查看功能的聊天应用程序.

I developing some kind of chat application with PDF viewing functions on Flutter for Android and Linux desktop platforms.

所以我想使用某种PDF阅读器或WebBrowser将PDF查看器嵌入到flutter应用程序中.Android上的PDF没问题-pub.dev上有100多个用于PDF和WebView的插件,但是它们都不支持Linux桌面.

So i want to embed PDF viewer in flutter application using some kind of PDF reader or WebBrowser. There is no problems with PDF's on Android - more than 100 plugins on pub.dev for PDF's and WebViews, but none of them supported Linux desktop.

我试图添加对Android和IOS插件的Linux桌面支持,但是看起来它们都使用PlatformView和webview_flutter类,但它们在Linux桌面上尚不支持: PlatformView .它们具有P4优先级,并且未分配里程碑.我不能无限期地等待,我应该在2个月内结束这个项目.那我该怎么办?

I have tried to add Linux desktop support for Android and IOS plugins, but look's like all of them using PlatformView and webview_flutter classes, which not supported on Linux desktop yet: webview_flutter PlatformView. They have P4 priority and no milestone assigned. I can't wait undefinitely long time, i should end this project in 2 months. So what should i do?

我已经读过Flutter使用GTK +在Linux桌面上显示,我知道有

I have read that Flutter uses GTK+ to display on Linux desktop, and i know that there is GTK+ components to display PDF. So is it possible to inject somehow this component in flutter ui? Is there any example?

也许将jpeg中的PDF转换为图像而不显示图像会更好?(但我不想失去缩放和文档导航功能)

Or maybe better will be to convert PDF in jpeg and show images instead? (But i don't want lost zoom and document navigation)

使用File.Open()将PDF打开到外部程序中对我来说不是解决方案,因为在这种情况下,用户应不断在flutter应用程序(我们有PDF文件列表的应用程序)和PDF阅读器窗口之间进行切换.

Opening PDF into external program with File.Open() is not solution for me, because in this case user's should constantly switch between flutter app (where we have list of PDF files) and PDF reader windows.

我对Flutter和Linux都是陌生的,因此将不胜感激.

I am new to both Flutter and Linux, so any help would be appreciated.

推荐答案

因此,为了阐明我们如何使用webkit实现此目的,例如:

So just to clarify how we can achive this using webkit, as example:

CMakeLists.txt:

CMakeLists.txt:

#add webkit package reference
pkg_check_modules(WEBKIT2 REQUIRED IMPORTED_TARGET webkit2gtk-4.0)
...
#remove -Werror flag to allow compilation with warnings
target_compile_options(${TARGET} PRIVATE -Wall)
...
#link webkit libraries
target_link_libraries(${BINARY_NAME} PUBLIC PkgConfig::WEBKIT2) 
#somehow this line causes 'flutter run' to crash on "Linking CXX executable" step.
#Looks like it compiles, but fails to link. 
#I think there is should be other question opened for this issue. 

my_application.cc:

my_application.cc:

#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
#include <webkit2/webkit2.h>
#include "flutter/generated_plugin_registrant.h"

static void my_application_activate(GApplication* application) {

  GtkWidget *vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox1);

  // we can insert any gtk controls in this window outside of FlView
  GtkWidget *label = gtk_label_new ("Hello GNOME!");
  gtk_box_pack_start (GTK_BOX (vbox1), label, TRUE, TRUE, 2);
  gtk_widget_show (label);

  // webkit/poppler/evince should work perfect because they gtk+
  WebKitWebView *pWebKitView = WEBKIT_WEB_VIEW(webkit_web_view_new());
  gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET(pWebKitView), TRUE, TRUE, 2);
  gtk_widget_show(GTK_WIDGET(pWebKitView));

  // finally add FlView
  g_autoptr(FlDartProject) project = fl_dart_project_new();
  FlView *view = fl_view_new(project);
  gtk_box_pack_start (GTK_BOX (vbox1), GTK_WIDGET(view), TRUE, TRUE, 2);
  gtk_widget_show (GTK_WIDGET (view));

  GtkWindow* window =
  GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
  gtk_container_add (GTK_CONTAINER (window), vbox1);

  fl_register_plugins(FL_PLUGIN_REGISTRY(view));
  gtk_widget_grab_focus(GTK_WIDGET(view));

  GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
  gtk_widget_show(GTK_WIDGET(header_bar));
  gtk_header_bar_set_title(header_bar, "client");
  gtk_header_bar_set_show_close_button(header_bar, TRUE);
  gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
  gtk_window_set_default_size(window, 1280, 720);

  gtk_widget_show(GTK_WIDGET(window));
}

这篇关于适用于Linux桌面的Flutter PDF Viewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆