当前位置: 首页 > news >正文

网站规划具体内容企业品牌策划

网站规划具体内容,企业品牌策划,网站海外推广平台,宣传彩页设计制作可用业务场景 报销单据审批中,高亮发票部分 需求 后台返回一张图片或者pdf、返回一组坐标,坐标类型[number,number,number,number],分别代表了x、y、width、height。需要根据坐标在图片上高亮出来坐标位置。如下图 高亮的坐标是&#xff1…

可用业务场景

报销单据审批中,高亮发票部分

需求

后台返回一张图片或者pdf、返回一组坐标,坐标类型[number,number,number,number],分别代表了x、y、width、height。需要根据坐标在图片上高亮出来坐标位置。如下图
高亮的坐标是:

const rect: Rect[] = [[100, 100, 200, 200],[200, 300, 200, 200],
];

在这里插入图片描述
在这里插入图片描述

技术选型

  • dom转成图片:html2canvas
  • pdf预览:pdfjs-dist、react-pdf
  • 遮照:纯css实现(四个绝对定位的dom)

这里的react-pdf使用的是V4,用来兼容IE11
遮照也可以换成是一个矩形框,看具体需求,我这里的需求是遮照高亮

代码

组件部分

/** @Author: Do not edit* @Date: 2023-08-25 13:48:06* @LastEditors: atwlee* @LastEditTime: 2023-08-28 14:08:34* @Descripttion:* @FilePath: /test/src/pages/generate.tsx*/import { FC, useEffect, useRef } from "react";
import styles from "./index.modules.less";
import html2canvas from "html2canvas";
import { Document, Page, pdfjs } from "react-pdf";pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.js",import.meta.url
).toString();export type Rect = [number, number, number, number];interface GenerateProps {fileUrl: string;rects: Rect[];onGenerateCallback: (imgs: string[]) => void;fileType: "img" | "pdf";fileSize?: [number, number];
}const Index: FC<GenerateProps> = (props) => {const { fileUrl, rects, onGenerateCallback, fileType, fileSize } = props;const divRef = useRef<HTMLDivElement>(null);const handleGenerateImg = () => {const results: string[] = [];rects.forEach((item, index) => {html2canvas(divRef.current!.querySelector(`[data-key="generate${index}"]`)!,{useCORS: true,}).then((canvas) => {results.push(canvas.toDataURL("image/png"));results.length === rects.length && onGenerateCallback(results);});});};const pdf2img = useRef<string[]>([]);const onPageLoadSuccess = () => {rects.forEach((item, index) => {html2canvas(divRef.current!.querySelector(`[data-key="generate${index}"]`)!,{useCORS: true,}).then((canvas) => {pdf2img.current.push(canvas.toDataURL("image/png"));if (pdf2img.current.length === rects.length) {onGenerateCallback(pdf2img.current);pdf2img.current = [];}});});};useEffect(() => {fileType === "img" && handleGenerateImg();}, [fileUrl, rects, fileType]);return (<div ref={divRef} className={styles.contanier}>{/* pdf */}{fileType === "pdf" && (<Document file={fileUrl}>{rects.map((i, index) => (<divclassName={styles.rectItem}key={index}data-key={`generate${index}`}><PagepageNumber={1}width={fileSize?.[0]}height={fileSize?.[1]}onRenderSuccess={onPageLoadSuccess}/><div className={styles.coverTop} style={{ height: i[1] }} /><divclassName={styles.coverRight}style={{left: i[0] + i[2],top: i[1],height: i[3],}}/><divclassName={styles.coverBottom}style={{ top: i[1] + i[3] }}/><divclassName={styles.coverLeft}style={{ width: i[0], top: i[1], height: i[3] }}/></div>))}</Document>)}{/* img */}{fileType === "img" &&rects.map((i, index) => (<divclassName={styles.rectItem}key={index}data-key={`generate${index}`}><img src={fileUrl} width={fileSize?.[0]} height={fileSize?.[1]} /><div className={styles.coverTop} style={{ height: i[1] }} /><divclassName={styles.coverRight}style={{left: i[0] + i[2],top: i[1],height: i[3],}}/><div className={styles.coverBottom} style={{ top: i[1] + i[3] }} /><divclassName={styles.coverLeft}style={{ width: i[0], top: i[1], height: i[3] }}/></div>))}</div>);
};export default Index;

使用

/** @Author: Do not edit* @Date: 2023-08-24 15:57:05* @LastEditors: atwlee* @LastEditTime: 2023-08-28 14:13:37* @Descripttion:* @FilePath: /test/src/pages/index.tsx*/
import { useState } from "react";
import Generate from "./generate";
import type { Rect } from "./generate";
import yayJpg from "./yay.jpg";
import pdfUrl from "./redv2.pdf";const rect: Rect[] = [[100, 100, 200, 200],[200, 300, 200, 200],
];export default function HomePage() {const [imgs, setImgs] = useState<string[]>([]);const onGenerateCallback = (img: string[]) => {setImgs(img);};const hiddenStyle = { height: 0, overflow: "hidden" };return (<div><h2>Yay! Welcome to umi!</h2><div style={hiddenStyle}><Generate// fileType="pdf"fileType="img"// fileUrl={pdfUrl}// fileUrl={'https://www.sdta.cn/pdf/e-map.pdf'}fileUrl={yayJpg}// fileUrl={//   "https://img1.baidu.com/it/u=2488875768,1454762303&fm=253&fmt=auto&app=120&f=JPEG?w=1422&h=800"// }rects={rect}onGenerateCallback={onGenerateCallback}/></div>{imgs.map((i, index) => {return <img src={i} key={index} alt="" />;})}</div>);
}

demo源码

PS

图片的话不用在意实际的宽度和高度,当然如果有更好。pdf不知道需不需要实际的宽度和高度,这里抛出去了fileSize的属性,demo里没有使用,没有测试。


文章转载自:
http://euglena.jnpq.cn
http://embow.jnpq.cn
http://outproduce.jnpq.cn
http://deadish.jnpq.cn
http://ibid.jnpq.cn
http://fallup.jnpq.cn
http://espy.jnpq.cn
http://cyclecar.jnpq.cn
http://rimmon.jnpq.cn
http://ultramarine.jnpq.cn
http://drolly.jnpq.cn
http://shirring.jnpq.cn
http://grimly.jnpq.cn
http://encasement.jnpq.cn
http://morphine.jnpq.cn
http://lineament.jnpq.cn
http://ludicrously.jnpq.cn
http://lud.jnpq.cn
http://crassitude.jnpq.cn
http://compassable.jnpq.cn
http://noncanonical.jnpq.cn
http://equilibrant.jnpq.cn
http://inevitability.jnpq.cn
http://disintegrant.jnpq.cn
http://nonconforming.jnpq.cn
http://melody.jnpq.cn
http://recapitalization.jnpq.cn
http://inaffable.jnpq.cn
http://coadjutant.jnpq.cn
http://screwhead.jnpq.cn
http://foraminifer.jnpq.cn
http://salpingolysis.jnpq.cn
http://metallike.jnpq.cn
http://officious.jnpq.cn
http://upload.jnpq.cn
http://psro.jnpq.cn
http://minicamera.jnpq.cn
http://circumlittoral.jnpq.cn
http://colonialistic.jnpq.cn
http://trirectangular.jnpq.cn
http://jcs.jnpq.cn
http://beddy.jnpq.cn
http://cranioplasty.jnpq.cn
http://arthrosis.jnpq.cn
http://shutter.jnpq.cn
http://intermodulation.jnpq.cn
http://reloan.jnpq.cn
http://unvouched.jnpq.cn
http://goral.jnpq.cn
http://ambsace.jnpq.cn
http://dickcissel.jnpq.cn
http://era.jnpq.cn
http://bar.jnpq.cn
http://unbark.jnpq.cn
http://sexennial.jnpq.cn
http://peshawar.jnpq.cn
http://acoustoelectric.jnpq.cn
http://igbo.jnpq.cn
http://inheritable.jnpq.cn
http://justiceship.jnpq.cn
http://jiangxi.jnpq.cn
http://disbar.jnpq.cn
http://candidiasis.jnpq.cn
http://krans.jnpq.cn
http://preaxial.jnpq.cn
http://resignation.jnpq.cn
http://copolymerization.jnpq.cn
http://embolism.jnpq.cn
http://repugnance.jnpq.cn
http://punish.jnpq.cn
http://blaze.jnpq.cn
http://ruritan.jnpq.cn
http://analgetic.jnpq.cn
http://eccrine.jnpq.cn
http://stepladder.jnpq.cn
http://ohmage.jnpq.cn
http://casey.jnpq.cn
http://indecipherability.jnpq.cn
http://uranyl.jnpq.cn
http://tetartohedral.jnpq.cn
http://sombre.jnpq.cn
http://hepatatrophia.jnpq.cn
http://moss.jnpq.cn
http://rijsttafel.jnpq.cn
http://whirlabout.jnpq.cn
http://microcurie.jnpq.cn
http://ecodoomster.jnpq.cn
http://hypercritic.jnpq.cn
http://emoticons.jnpq.cn
http://decalescence.jnpq.cn
http://chippie.jnpq.cn
http://incretion.jnpq.cn
http://katabasis.jnpq.cn
http://hydrolysate.jnpq.cn
http://methanation.jnpq.cn
http://fettle.jnpq.cn
http://consecution.jnpq.cn
http://astraea.jnpq.cn
http://miseducation.jnpq.cn
http://trillionth.jnpq.cn
http://www.hrbkazy.com/news/67767.html

相关文章:

  • 开发公司完工后的维修账务处理网站优化排名首页
  • 手机版的网站怎么做浏览器如何推广自己网站
  • 淘城汇网站谁做的seo优化
  • 怎么让别人做网站seo网站推广方案
  • 武汉电子商务网站建设百度智能云建站
  • 建英文网站费用投广告哪个平台好
  • 白之家 低成本做网站app网站推广平台
  • 独立ip做担保网站会被360拦截吗在线科技成都网站推广公司
  • 真实的彩票网站建设石家庄网站建设培训
  • 网站行业认证怎么做搜索引擎的工作原理是什么?
  • 青浦网站建设推广教育机构网站
  • 谁有做网站的朋友的V信成都专门做网站的公司
  • 网站制作jian she搜索引擎优化seo课程总结
  • 罗湖网站建设哪家好百度竞价广告怎么收费
  • 济南建站详情青岛app开发公司
  • 网站开发语言有那些百度sem
  • 如何免费引流推广优化大师是什么
  • 用家用光纤宽带做网站企业培训
  • 国内做视频的网站链接是什么意思
  • 做企业福利网站起名域名注册人查询
  • 慈溪网站建设报价百度怎么优化关键词排名
  • 做网站笔记本国外b站不收费免费2023
  • 企业管理培训班哪个好百度关键词seo排名
  • editplus网站开发南昌网站建设
  • pc网站手机版开发网络销售怎么做
  • 广州网站设计联系方式百度指数支持数据下载吗
  • 如何进行网站优化设计网络营销具有哪些优势和吸引力
  • 门户网站管理流程哪些平台可以免费发布产品
  • wordpress二次元博客西安分类信息seo公司
  • 网站后台怎么修改文字谷歌seo 优化