我需要一种在我的Reaction应用程序中显示PDF的方式,并满足以下要求:

  • 能够以编程方式设置页面
  • 在PDF中搜索文本(基本上是Ctrl+F)
  • 突出显示PDF中的文本

我找到了ngx-extended-pdf-viewer的包裹,但看起来是给安吉尔的.https://www.npmjs.com/package/ngx-extended-pdf-viewer

I've never used Angular before, but since it's still just a node package can I import and use it in React just like any other package?

我try 使用包中的组件:

import React from "react";
import { NgxExtendedPdfViewerComponent } from "ngx-extended-pdf-viewer";

const NGXPDFViewer = () => {
  return (
    <NgxExtendedPdfViewerComponent
      src={
        "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
      }
      useBrowserLocale="true"
    ></NgxExtendedPdfViewerComponent>
  );
};

export default NGXPDFViewer;

但是,我得到以下错误:

Module not found: Error: Can't resolve '@angular/platform-browser'

Module not found: Error: Can't resolve '@angular/forms'

Before I go trying to install Angular modules inside a React app, can someone let me know if this is even possible?我真的很想使用ngx-extended-pdf-viewer套餐,因为它是我找到的唯一一个具有搜索和PageNumber功能的套餐.(文本突出显示我或许可以自己使用css)

如果这类似于苹果和橙子的混合,那么我就到此为止了.

推荐答案

这是不可能的.原因:ReactAngular104.因此,您编写代码,然后他们将其呈现为(对于浏览器)可读的htmljavascript.它们还可以做更多的事情:自动刷新、双向绑定、状态管理.

所有这些都是每个框架中的大代码部分.

长话短说:Reaction永远不知道如何处理这未知的angular code.而安吉尔永远不会知道如何处理这一未知的react code.

你不能以这种方式混合它.

一些解决方案

  1. 微框架-Web组件.你可以创建带有Angular (read个以上)的网页组件(@angular/elements),并在你的Reaction应用程序中添加一个网页组件.一个很好的解决方案--但需要一点工作.
Very short example:

create project(先安装Angular CLI!!)

ng new angular-web-component
cd angular-web-component

add Angular elements

ng add @angular/elements

create a component (which can include the pdf viewer)

ng generate component my-web-component

add it into 100

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Injector } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { MyWebComponentComponent } from './my-web-component/my-web-component.component';

@NgModule({
  declarations: [MyWebComponentComponent],
  imports: [BrowserModule],
  entryComponents: [MyWebComponentComponent]
})
export class AppModule {
  constructor(private injector: Injector) {}

  ngDoBootstrap() {
    const webComponent = createCustomElement(MyWebComponentComponent, { injector: this.injector });
    customElements.define('my-web-component', webComponent);
  }
}

build the angular project

ng build --prod --output-hashing none

6. Use in React:

将dist/目录中生成的JS文件添加到您的Reaction项目中.这可以通过在HTML中包含标记或通过其他方式来实现.

然后,您可以在您的Reaction代码中使用Web组件,如下所示:

function App() {
  return (
    <div className="App">
      <my-web-component></my-web-component>
    </div>
  );
}
  1. 使用pdf组件构建一个小Angular 的应用程序,构建它,然后将其添加到您的Reaction应用程序中.

Angular相关问答推荐

Angular Signal只指一种类型,但这里用作值.ts(2693)''

如何在Angular中执行一个操作条件为多个可观测值?

在Angular 多选下拉菜单中实现CDK拖放排序的问题

元素上的Angular 管道链接不起作用

所有返回缺少权限或权限不足的FireBase项目.

IonicStorageModule似乎不是 NgModule 类

显示带有数组子列的标题表 - Angular

ng 生成组件不会创建 ngOnInit 和构造函数

带有数据的 Angular 模板

从 angular 11 升级到 angular 12 后,我的项目没有使用优化参数进行编译

缺少 .angular-cli.json 文件:Angular

visibility:hidden

如何在 Angular2 中的所有请求的请求标头中发送Cookie?

移除 Angular 组件创建的宿主 HTML 元素 Select 器

如何提高 Angular2 应用程序的加载性能?

unexpected token < 错误

有条件地将 RouterLink 或其他属性指令添加到 Angular 2 中的元素

在 Angular 2 中使用逗号作为列表分隔符

升级到 angular-6.x 会给出Uncaught ReferenceError: global is not defined

ngClass 中的多个条件 - Angular 4