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

网站的内连接如何做肇庆seo

网站的内连接如何做,肇庆seo,北京师大互联网公司,如何查找高权重网站PDF修改尺寸 需要注意:第一个方法返回的是转换后PDF的base64。第二个方法返回的是文件流,这个方法才是转的核心。 /*** 修改PDF尺寸** param pdfUrl PDF链接* param pdfWidthInMillimeters 指定宽 mm* param pdfHeightInMillimeters 指…

PDF修改尺寸

需要注意:第一个方法返回的是转换后PDF的base64。第二个方法返回的是文件流,这个方法才是转的核心。

 /*** 修改PDF尺寸** @param pdfUrl                 PDF链接* @param pdfWidthInMillimeters  指定宽 mm* @param pdfHeightInMillimeters 指定高 mm* @return PDF转换尺寸后的base64*/public static String updatePdfSize(String pdfUrl, float pdfWidthInMillimeters, float pdfHeightInMillimeters) {try {URL url = new URL(pdfUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();conn.setRequestMethod("GET");conn.setConnectTimeout(5000);InputStream is = conn.getInputStream();ByteArrayOutputStream out = updatePdfSize(is, pdfWidthInMillimeters, pdfHeightInMillimeters);BASE64Encoder encoder = new BASE64Encoder();String pdfBase64 = encoder.encode(out.toByteArray());is.close();return pdfBase64;} catch (IOException e) {log.error("updatePdfSize error:{}", e.getMessage(), e);}return "";}/*** 转换PDF尺寸** @param inputStream            PDF源文件流* @param pdfWidthInMillimeters  指定宽 mm* @param pdfHeightInMillimeters 指定高 mm* @return 转换后的PDF的文件流*/public static ByteArrayOutputStream updatePdfSize(InputStream inputStream, float pdfWidthInMillimeters, float pdfHeightInMillimeters) {try {// 毫米转换为磅(1毫米≈2.83465磅)float pdfWidthInPoints = pdfWidthInMillimeters * 2.83465f;float pdfHeightInPoints = pdfHeightInMillimeters * 2.83465f;//  容器初始化ByteArrayOutputStream out = new ByteArrayOutputStream();Document doc = new Document();PdfWriter writer = PdfWriter.getInstance(doc, out);doc.open();PdfReader pdfReader = new PdfReader(inputStream);PdfContentByte cb = writer.getDirectContent();// 循环修改尺寸int total = pdfReader.getNumberOfPages();for (int i = 1; i <= total; i++) {PdfImportedPage page = writer.getImportedPage(pdfReader, i);Rectangle rectangle = pdfReader.getPageSize(i);float originalWidth = rectangle.getWidth();float originalHeight = rectangle.getHeight();// 计算缩放比例float scaleWidth = pdfWidthInPoints / originalWidth;float scaleHeight = pdfHeightInPoints / originalHeight;float scale = Math.min(scaleWidth, scaleHeight);doc.setPageSize(new RectangleReadOnly(originalWidth * scale, originalHeight * scale));doc.newPage();cb.addTemplate(page, scale, 0, 0, scale, 0, 0);}doc.close();writer.close();return out;} catch (Exception e) {log.error("updatePdfSize error:{}", e.getMessage(), e);return null;}}

图片转成指大小PDF

返回的是base64。需要返回流的,可能简单改写下

/*** 图片转成指定大小的PDF的base64** @param pngImagePath           图片地址* @param pdfWidthInMillimeters  指定的PDF宽(mm)* @param pdfHeightInMillimeters 指定的PDF高(mm)* @return PDF的Base64*/public static String convertPngToPdfBase64(String pngImagePath, float pdfWidthInMillimeters, float pdfHeightInMillimeters) {try {// 毫米转换为磅(1毫米≈2.83465磅)float pdfWidthInPoints = pdfWidthInMillimeters * 2.83465f;float pdfHeightInPoints = pdfHeightInMillimeters * 2.83465f;// 读取PNG图像的原始宽度和高度(单位:点)Image pngImage = Image.getInstance(pngImagePath);float originalWidth = pngImage.getWidth();float originalHeight = pngImage.getHeight();// 计算图像在PDF中的缩放比例float scaleWidth = pdfWidthInPoints / originalWidth;float scaleHeight = pdfHeightInPoints / originalHeight;float scale = Math.min(scaleWidth, scaleHeight);// 计算图像在PDF中的位置居中显示float xPosition = (pdfWidthInPoints - originalWidth * scale) / 2;float yPosition = (pdfHeightInPoints - originalHeight * scale) / 2;// 创建Document对象,并设置PDF文档的大小为所需尺寸Document document = new Document(new Rectangle(pdfWidthInPoints, pdfHeightInPoints));// 创建PdfWriter对象,将输出流与Document对象关联ByteArrayOutputStream os = new ByteArrayOutputStream();PdfWriter.getInstance(document, os);// 打开Documentdocument.open();// 设置PNG图像在PDF中的缩放比例和位置pngImage.scaleAbsolute(originalWidth * scale, originalHeight * scale);pngImage.setAbsolutePosition(xPosition, yPosition);// 将PNG图像添加到PDF中document.add(pngImage);// 关闭Documentdocument.close();// 返回PDF的base64return new BASE64Encoder().encode(os.toByteArray()).trim().replaceAll("\\r", "").replaceAll("\\n", "");} catch (DocumentException | IOException e) {log.error("image 转 pdf 流失败 {}", e.getMessage(), e);return "";}}
http://www.zhongyajixie.com/news/12263.html

相关文章:

  • 武汉seo优化厂家网站内容优化关键词布局
  • 怎样建外贸公司网站怎么做百度推广运营
  • 适合学生做的网站seo思维
  • 体育直播网站制作开发深圳优化排名公司
  • 电气网站建设快速建站哪个平台好
  • 做国外网站翻译中国小说赚钱抖音seo查询工具
  • 网站建设细节东莞网站营销推广
  • 网站开发前端招聘百度下载安装免费版
  • 网站文章快速被收录艾滋病多长时间能查出来
  • 玉溪的网站建设公司网站建设技术
  • 西安网站建设公对网络营销的认识有哪些
  • 网站做目录免费加精准客源
  • 自己做家具网站百度官网首页入口
  • 网站开发需求文档模板全国广告投放平台
  • 成品短视频app有哪些合肥网站seo
  • 温州网站建设方案维护网络推广合作协议范本
  • 北京城乡建设委员会网站网络服务器配置与管理
  • 网站做二级站网络营销的招聘信息
  • 特殊符号网站网络营销推广公司名称
  • 网站备案 空间国家市场监管总局
  • 游戏定制公司优化20条措施
  • 花店网站建设实训总结品牌咨询
  • 哈尔滨做网站优化品牌推广内容
  • 河北网络公司网站建设seo技术分享
  • 北京工信部查网站备案百度购物平台客服电话
  • 网站错误页面模板现在有哪些推广平台
  • 滁州做网站价格河北高端网站建设
  • 做网站算软件行业吗关键词优化意见
  • 如何制作一个简单的网站哪个网站是免费的
  • 管理系统网站开发报价seo推广服务