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

做网站用什么配置的电脑网站打开空白页

做网站用什么配置的电脑,网站打开空白页,php网站模板使用,做a暧小视频在线观看网站1、问题描述 需要将发票导出成pdf#xff0c;要求每页都必须包含发票信息和表头行。 2、解决方法 使用IText工具实现PDF导出 IText8文档#xff1a;Examples (itextpdf.com) 3、我的代码 引入Itext依赖#xff0c;我这里用的是8.0.1版本 dependencygroupId…1、问题描述  需要将发票导出成pdf要求每页都必须包含发票信息和表头行。 2、解决方法 使用IText工具实现PDF导出 IText8文档Examples (itextpdf.com) 3、我的代码 引入Itext依赖我这里用的是8.0.1版本 dependencygroupIdcom.itextpdf/groupIdartifactIditext7-core/artifactIdversion8.0.1/versiontypepom/type/dependency MyItextpdfUtils.java package com.easyexcel.util;import com.easyexcel.handler.PaginationEventHandler; import com.itextpdf.html2pdf.HtmlConverter; import com.itextpdf.io.font.PdfEncodings; import com.itextpdf.io.image.ImageData; import com.itextpdf.io.image.ImageDataFactory; import com.itextpdf.kernel.events.PdfDocumentEvent; import com.itextpdf.kernel.font.PdfFont; import com.itextpdf.kernel.font.PdfFontFactory; import com.itextpdf.kernel.geom.PageSize; import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.layout.Document; import com.itextpdf.layout.borders.Border; import com.itextpdf.layout.element.*; import com.itextpdf.layout.element.Image; import com.itextpdf.layout.properties.AreaBreakType; import com.itextpdf.layout.properties.TextAlignment; import com.itextpdf.layout.properties.UnitValue; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component;import java.awt.*; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map;/*** author Wulc* date 2023/8/10 17:08* description*/ Component public class MyItextpdfUtils {public void createPDF() throws java.io.IOException {Resource resource new ClassPathResource(/);String path resource.getFile().getPath();//设置中文字体 C:\Windows\Fonts//PdfFont chineseFont getFont();//PdfFont chineseFont PdfFontFactory.createFont(this.getClass().getClassLoader().getResource(simsun.ttf).getPath());PdfFont chineseFontForTemplate PdfFontFactory.createFont(D:\\学习资料\\后端\\STSONG.TTF);PdfFont chineseFontForContent PdfFontFactory.createFont(D:\\学习资料\\后端\\STSONG.TTF);//创建每页的共有模板//*********************每页的共有模板*********************************String templatePath path \\template.pdf;PdfDocument pdfDocumentTemplate new PdfDocument(new PdfWriter(templatePath));//Document documentTemplate new Document(pdfDocumentTemplate, PageSize.A4).setFont(chineseFontForTemplate);Document documentTemplate new Document(pdfDocumentTemplate, PageSize.A4);//插入logo图片Table logoTemplateTable new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth().setBorder(Border.NO_BORDER);ImageData imageData ImageDataFactory.create(this.getClass().getClassLoader().getResource(logo.png));Image image new Image(imageData);image.setHeight(50);image.setWidth(100);logoTemplateTable.addCell(new Cell().setBorder(Border.NO_BORDER).add(image));//插入logo图片下方的一些信息Table logoInfoTable new Table(UnitValue.createPercentArray(1)).useAllAvailableWidth().setBorder(Border.NO_BORDER);logoInfoTable.addCell(new Cell().setBorder(Border.NO_BORDER).setPadding(1).setFontSize(10).add(new Paragraph(Description1)));logoInfoTable.addCell(new Cell().setBorder(Border.NO_BORDER).setPadding(1).setFontSize(10).add(new Paragraph(Description2)));logoInfoTable.addCell(new Cell().setBorder(Border.NO_BORDER).setPadding(1).setFontSize(10).add(new Paragraph(Description3)));//插入标题Table titleTable new Table(UnitValue.createPercentArray(4)).useAllAvailableWidth().setBorder(Border.NO_BORDER);titleTable.addCell(new Cell(1, 4).setBorder(Border.NO_BORDER).setPadding(1).setFontSize(15).add(new Paragraph(TITLE)).setTextAlignment(TextAlignment.CENTER));//插入标题下的一些信息Table titleInfoTable new Table(UnitValue.createPercentArray(4)).useAllAvailableWidth();titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionA)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerA)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionB)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerB)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionC)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerC)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionD)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerD)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionE)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerE)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(QuestionF)));titleInfoTable.addCell(new Cell().setPadding(1).setFontSize(10).add(new Paragraph(AnswerF)));documentTemplate.add(logoTemplateTable);documentTemplate.add(logoInfoTable);documentTemplate.add(titleTable);documentTemplate.add(titleInfoTable);//*********************每页的共有模板*********************************//*********************每页的内容************************************String contentPath path \\content.pdf;PdfDocument pdfDocumentContent new PdfDocument(new PdfWriter(contentPath));//把内容使用共有模板pdfDocumentContent.addEventHandler(PdfDocumentEvent.END_PAGE, new PaginationEventHandler(pdfDocumentTemplate.getFirstPage().copyAsFormXObject(pdfDocumentContent)));Document documentContent new Document(pdfDocumentContent, PageSize.A4).setFont(chineseFontForContent);//每页的content距离上面的template的距离documentContent.setTopMargin(250);Table contentTable new Table(UnitValue.createPercentArray(6)).useAllAvailableWidth();//插入清单表格标题contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(No)));contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(title1)));contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(title2)));contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(title3)));contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(title4)));contentTable.addHeaderCell(new Cell().setFontSize(8).add(new Paragraph(title5)));for (int i 0; i 300; i) {contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(String.valueOf(i))));contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(content1)));contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(content2)));contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(content3)));contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(content4)));contentTable.addCell(new Cell().setFontSize(8).add(new Paragraph(content5)));}//尾页Table lastInfoTable new Table(UnitValue.createPercentArray(3)).setWidth(300);lastInfoTable.addCell(new Cell(1, 3).setPadding(1).setFontSize(8).add(new Paragraph(Total)));lastInfoTable.addCell(new Cell(1, 1).setPadding(1).setFontSize(8).add(new Paragraph(统计A)));lastInfoTable.addCell(new Cell(1, 2).setPadding(1).setFontSize(8).add(new Paragraph(1234567)));lastInfoTable.addCell(new Cell(1, 1).setPadding(1).setFontSize(8).add(new Paragraph(统计B)));lastInfoTable.addCell(new Cell(1, 2).setPadding(1).setFontSize(8).add(new Paragraph(7654321)));//*********************每页的内容************************************documentContent.add(contentTable);//尾页新开一页documentContent.add(new AreaBreak(AreaBreakType.NEXT_PAGE));documentContent.add(lastInfoTable);documentTemplate.close();documentContent.close();}}PDFTest.java​​​​​​​ package com.easyexcel;import com.easyexcel.util.MyItextpdfUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner;import java.io.IOException;/*** author Wulc* date 2023/8/10 17:52* description*/ SpringBootTest(classes SpringbootApplication.class) RunWith(SpringRunner.class) public class PDFTest {Autowiredprivate MyItextpdfUtils myItextpdfUtils;Testpublic void test6() throws IOException {myItextpdfUtils.createPDF();} }测试一下 4、总结 IText8不支持中文需要引入外部字体文件如果是以其中一个pdf作为每页的背景模板生成PDF这种方式copyAsFormXObject它只能支持其中一个pdf中文另一个就不支持了。 Document documentTemplate new Document(pdfDocumentTemplate, PageSize.A4).setFont(chineseFontForTemplate); Document documentContent new Document(pdfDocumentContent, PageSize.A4).setFont(chineseFontForContent); 如上代码虽然我同时把背景版和内容同时都设置了中文字体但是template和content合一块的时候template的背景版pdf的中文字体就会失效了。 不过还好因为是海外的发票都是英文的因此不需要考虑支持中文的问题。 希望哪位大佬能帮忙解决一下IText8 copyAsFormXObject中文兼容性问题 5、参考资料 https://www.cnblogs.com/sky-chen/p/13026203.html#autoid-1-4-5-0-0-0 https://kb.itextpdf.com/home/it7kb/examples/repeating-parts-of-a-form https://zhuanlan.zhihu.com/p/537723847 https://blog.csdn.net/weixin_43409994/article/details/118157694 https://blog.csdn.net/u012397189/article/details/126345744 https://blog.csdn.net/Thinkingcao/article/details/84988392
http://www.zqtcl.cn/news/581545/

相关文章:

  • 金华网站建设明细报价表c苏宁网站开发
  • 在手机上怎么做微电影网站湖南人工智能建站系统软件
  • 网站做的一样算侵权吗站群建站系统
  • 骨干专业建设验收网站xueui wordpress
  • 宁波高质量品牌网站设计厂家世界上有php应用的网站
  • 网站平台建设的重要性响应式网站切图
  • 近期做网站需要什么软件网站制作常见的问题
  • vs做的本地网站甘肃省建设厅门户网站
  • 网站建设合同义务wordpress m1
  • 青海省建设局网站首页wordpress模板建站教程视频
  • 演示 又一个wordpress站点静态页面加wordpress
  • 企业做淘宝客网站有哪些有网站吗给一个
  • 深圳网站制作公司信息之梦与wordpress哪个好用
  • 免费搭建商城网站山西制作网站公司排名
  • 网站开发免费中建建设银行网站
  • 301重定向到新网站在线建站
  • 曰本做爰l网站沙朗做网站公司
  • 广州网站设计智能 乐云践新专家wordpress 头像设置
  • 电子商务学网站建设好吗佛山市手机网站建设企业
  • 为企业做网站电话开场白小说网站的里面的搜索是怎么做的
  • 深圳市设计网站公司自己做网站开网店
  • 智能建站cms管理系统修改wordpress时区
  • 站长怎么添加网站内容重庆网站推
  • 东莞网站建设属于什么专业网页设计代码书
  • 网站后台代码在哪修改wordpress添加搜索小工具
  • 爱站站长工具中国建设监理协会官方网站
  • 珠海微信网站开发东莞网站制作方案定制
  • 大学网站建设说明书记的网站域名
  • 网站如何开通支付功能第一ppt课件免费下载官网
  • 做1元夺宝网站挣钱吗美工网站设计收费