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

长春市建设信息网站b站推广引流最佳方法

长春市建设信息网站,b站推广引流最佳方法,网站建设与网站开发,广州海珠做网站的公司​ 最近接到用户提过来的需求,需要一个能够自动打印图纸的功能,经过几天的研究整出来个初版了的,分享出来给大家,希望能有帮助。 需求描述: ​ 生产车间现场每天都有大量的图纸需要打印,一个一个打印太慢了&#xff0…

​ 最近接到用户提过来的需求,需要一个能够自动打印图纸的功能,经过几天的研究整出来个初版了的,分享出来给大家,希望能有帮助。
需求描述:

​ 生产车间现场每天都有大量的图纸需要打印,一个一个打印太慢了,希望可以有个批量打印的功能。
分析

​ 我们的图纸是存在服务器上,都是pdf版本的,所以批量打印程序可以通过文件名称,然后程序自动将共享文件推送到打印机上打印,这样就可以实现自动化了,并且后续还可以根据情况进行扩展

代码

初版的程序比较简单,使用的是springboot + spring shell 来实现,具体代码如下:

<!-- pom.xml 片段 -->
<!-- spring-boot-starter 版本是随意选的 -->
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.14</version>
</parent>
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- spring-shell 版本需要与 spring-boot-starter 匹配 --><dependency><groupId>org.springframework.shell</groupId><artifactId>spring-shell-starter</artifactId><version>2.1.11</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.26</version><optional>true</optional><scope>compile</scope></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.26</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.22</version></dependency></dependencies><build><finalName>DrawPrinter</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.5.4</version> <!-- 使用适合你的Spring Boot版本 --><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>

shell命令代码

package xxxx;import cn.hutool.core.util.StrUtil;
import com.higer.ipd.tools.drawprinter.commons.PdfPrinter;
import com.higer.ipd.tools.drawprinter.entity.DrawInfoEntity;
import com.higer.ipd.tools.drawprinter.service.IDrawInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;import java.io.File;
import java.util.HashMap;
import java.util.List;@ShellComponent
public class CommonCommand {@Autowiredprivate IDrawInfoService drawInfoService;@ShellMethod(value = "打印消息",key="000",group = "test")public void printMessage(String message) {System.out.println(message);}@ShellMethod(value = "查看本地打印机",key="101",group = "print")public void showLocPrinter(){PdfPrinter.getLocalPrinter().keySet().forEach(System.out::println);}@ShellMethod(value="打印图纸",key="103",group = "print")public void printPdf(String printerName,String fileName,String pageSize){try {String result = PdfPrinter.print(new File(fileName), printerName, pageSize);if(StrUtil.isBlank(result)){System.out.println("打印成功!");}else{System.out.println(result);}} catch (Exception e) {e.printStackTrace();System.out.println("打印出错!");}}
}

上面开发了两个shell命令:“查看本地打印机"和"打印图纸”.

打印图纸代码片段如下:

public static String print(File file, String printerName,String pageSize) throws Exception {if(StrUtil.isBlank(printerName) || file == null || !file.exists()){return "未指定打印机或待文件不存在,请确认!";}// 1.根据打印机名称找到对应的打印机服务,Map<String, PrintService> printerMap = getLocalPrinter();PrintService printService = printerMap.get(printerName);if(printService == null){return "没有找到指定的打印机!";}// 2.加载pdf文件,并设置打印配置,打印try (PDDocument document = PDDocument.load(file)){PrinterJob printJob = PrinterJob.getPrinterJob();printJob.setJobName(file.getName());printJob.setPrintService(printService);PDFPrintable pdfPrintable = new PDFPrintable(document, Scaling.SCALE_TO_FIT);Book book = new Book();PageFormat pageFormat = new PageFormat();pageFormat.setOrientation(PageFormat.PORTRAIT);//纵向pageFormat.setPaper(getPaper(pageSize));//设置纸张book.append(pdfPrintable, pageFormat, document.getNumberOfPages());printJob.setPageable(book);printJob.setCopies(1);//设置打印份数HashPrintRequestAttributeSet pars = new HashPrintRequestAttributeSet();pars.add(Sides.ONE_SIDED); //设置单双页printJob.print(pars);}return "";
}

效果

启动后进入输入命令状态,输入help可以看到帮助信息,效果如下:

在这里插入图片描述
输入 help 103 可以看到打印图纸的帮助信息,命令格式为: 103 打印机名称 文件名称 页面大小(A3/A4)

在这里插入图片描述
源码下载

http://www.dinnco.com/news/74684.html

相关文章:

  • 公司微网站怎么做的万能识图
  • 上海网站制作公司是什么海曙seo关键词优化方案
  • 兴国网站建设信息流广告代运营
  • 做高端企业网站北京网站托管
  • 网站建设步骤 教 程产品如何做网络推广
  • 用asp.net 做网站西安网约车平台
  • 智慧校园系统平台搜索引擎优化与关键词的关系
  • 服务专业的品牌建站公司网络广告设计
  • 东莞凤岗做网站深圳网络营销网站设计
  • 山东系统建站怎么用谷歌账号
  • 盘锦微商网站建设补习班
  • 品牌建设论文怎么写百度seo在线优化
  • 青岛网站制作公司排名做销售怎样去寻找客户
  • 利用云盘做网站东莞网络营销推广公司
  • 免费网站建设真有这样的好事深圳今日头条新闻
  • 邢台做移动网站价格国际新闻界期刊
  • 网站改版需要怎么做推广平台排行榜app
  • 医学网站建设方案今日热搜前十名
  • seo网站策划临沂森佳木业有限公司
  • 垫江做网站谷歌浏览器下载
  • 咸秧草做哪些网站免费域名申请网站大全
  • 云南SEO网站建设中国营销策划第一人
  • 商务网站建设的一般流程是什么搜索词和关键词
  • 做网站那个平台好网站关键词快速排名优化
  • 谷歌浏览器下载手机版seo案例分析及解析
  • 毕业设计做网站 答辩会问什么问题黄金网站软件app大全下载
  • 网站宣传专利被罚淘宝关键词排名查询工具免费
  • 鞍山网站建设找金航搜索优化seo
  • 体育西网站开发设计上海网络优化服务
  • 快彩网站开发百度爱采购排名