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

iText实战--在现有PDF上工作

6.1 使用PdfReader读取PDF

检索文档和页面信息

D:/data/iText/inAction/chapter03/image_direct.pdf
Number of pages: 1
Size of page 1: [0.0,0.0,283.0,416.0]
Rotation of page 1: 0
Page size with rotation of page 1: Rectangle: 283.0x416.0 (rot: 0 degrees)
Is rebuilt? false
Is encrypted? false

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfReader;public class PageInformation {/** The resulting text file with info about a PDF. */public static final String RESULT= "D:/data/iText/inAction/chapter06/page_info.txt";/*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args)throws DocumentException, IOException {// Inspecting PDFsPrintWriter writer = new PrintWriter(new FileOutputStream(RESULT));inspect(writer, "D:/data/iText/inAction/chapter03/image_direct.pdf");writer.close();}/*** Inspect a PDF file and write the info to a txt file* @param writer Writer to a text file* @param filename Path to the PDF file* @throws IOException*/public static void inspect(PrintWriter writer, String filename)throws IOException {PdfReader reader = new PdfReader(filename);writer.println(filename);writer.print("Number of pages: ");writer.println(reader.getNumberOfPages());Rectangle mediabox = reader.getPageSize(1);writer.print("Size of page 1: [");writer.print(mediabox.getLeft());writer.print(',');writer.print(mediabox.getBottom());writer.print(',');writer.print(mediabox.getRight());writer.print(',');writer.print(mediabox.getTop());writer.println("]");writer.print("Rotation of page 1: ");writer.println(reader.getPageRotation(1));writer.print("Page size with rotation of page 1: ");writer.println(reader.getPageSizeWithRotation(1));writer.print("Is rebuilt? ");writer.println(reader.isRebuilt());writer.print("Is encrypted? ");writer.println(reader.isEncrypted());writer.println();writer.flush();}
}

Page Size 页面大小

损坏的PDF

加密的PDF

使用PdfReader降低内存

部分读取

    /*** Do a full read of a PDF file* @param writer a writer to a report file* @param filename the file to read* @throws IOException*/public static void fullRead(PrintWriter writer, String filename)throws IOException {long before = getMemoryUse();PdfReader reader = new PdfReader(filename);reader.getNumberOfPages();writer.println(String.format("Memory used by full read: %d",getMemoryUse() - before));writer.flush();}/*** Do a partial read of a PDF file* @param writer a writer to a report file* @param filename the file to read* @throws IOException*/public static void partialRead(PrintWriter writer, String filename)throws IOException {long before = getMemoryUse();PdfReader reader = new PdfReader(new RandomAccessFileOrArray(filename), null);reader.getNumberOfPages();writer.println(String.format("Memory used by partial read: %d",getMemoryUse() - before));writer.flush();}

选择页面

PdfReader.selectPages("3");

PdfReader.selectPages("4-8");

执行selectPages()后,页数就变成选中的实际页数,要注意越界。

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;public class SelectPages {/** A resulting PDF file. */public static final String RESULT1 = "results/part2/chapter06/timetable_stamper.pdf";/** A resulting PDF file. */public static final String RESULT2 = "results/part2/chapter06/timetable_copy.pdf"; /*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args) throws IOException, DocumentException {PdfReader reader = new PdfReader("D:/data/iText/inAction/chapter03/movie_posters.pdf");reader.selectPages("4-8");manipulateWithStamper(reader);manipulateWithCopy(reader);}/*** Creates a new PDF based on the one in the reader* @param reader a reader with a PDF file* @throws IOException* @throws DocumentException*/private static void manipulateWithStamper(PdfReader reader)throws IOException, DocumentException {PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT1));stamper.close();}/*** Creates a new PDF based on the one in the reader* @param reader a reader with a PDF file* @throws IOException* @throws DocumentException*/private static void manipulateWithCopy(PdfReader reader)throws IOException, DocumentException {int n = reader.getNumberOfPages();Document document = new Document();PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT2));document.open();for (int i = 0; i < n;) {copy.addPage(copy.getImportedPage(reader, ++i));}document.close();}}

6.2 从PDF拷贝页面

导入页面

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;public class ImportingPages1 {/** The resulting PDF file. */public static final String RESULT= "D:/data/iText/inAction/chapter06/time_table_imported1.pdf";/*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args)throws IOException, DocumentException {// step 1Document document = new Document();// step 2PdfWriter writer= PdfWriter.getInstance(document, new FileOutputStream(RESULT));// step 3document.open();// step 4PdfPTable table = new PdfPTable(2);PdfReader reader = new PdfReader("D:/data/iText/inAction/chapter03/movie_posters.pdf");int n = reader.getNumberOfPages();PdfImportedPage page;for (int i = 1; i <= n; i++) {page = writer.getImportedPage(reader, i);table.addCell(Image.getInstance(page));}document.add(table);// step 5document.close();}
}

缩放和叠加页面

叠加PDF页面

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfGState;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;public class Layers {/** The resulting PDF. */public static final String SOURCE= "D:/data/iText/inAction/chapter06/layers_orig.pdf";/** The resulting PDF. */public static final String RESULT= "D:/data/iText/inAction/chapter06/layers.pdf";/** The movie poster. */public static final String RESOURCE= "E:/study/PDF/SourceCodeiText/itext-book/book/resources/img/loa.jpg";/*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args)throws IOException, DocumentException {new Layers().createPdf(SOURCE);// Create a readerPdfReader reader = new PdfReader(SOURCE);// step 1Document document = new Document(PageSize.A5.rotate());// step 2PdfWriter writer= PdfWriter.getInstance(document, new FileOutputStream(RESULT));// step 3document.open();// step 4PdfContentByte canvas = writer.getDirectContent();PdfImportedPage page;BaseFont bf= BaseFont.createFont(BaseFont.ZAPFDINGBATS, "", BaseFont.EMBEDDED);for (int i = 0; i < reader.getNumberOfPages(); ) {page = writer.getImportedPage(reader, ++i);canvas.addTemplate(page, 1f, 0, 0.4f, 0.4f, 72, 50 * i);canvas.beginText();canvas.setFontAndSize(bf, 20);canvas.showTextAligned(Element.ALIGN_CENTER,String.valueOf((char)(181 + i)), 496, 150 + 50 * i, 0);canvas.endText();}// step 5document.close();}/*** Creates a PDF document.* @param filename the path to the new PDF document* @throws    DocumentException * @throws    IOException*/public void createPdf(String filename)throws IOException, DocumentException {// step 1Document document = new Document(PageSize.POSTCARD, 30, 30, 30, 30);// step 2PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(filename));// step 3document.open();// step 4PdfContentByte under = writer.getDirectContentUnder();// Page 1: a rectangledrawRectangle(under, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());under.setRGBColorFill(0xFF, 0xD7, 0x00);under.rectangle(5, 5, PageSize.POSTCARD.getWidth() - 10, PageSize.POSTCARD.getHeight() - 10);under.fill();document.newPage();// Page 2: an imagedrawRectangle(under, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());Image img = Image.getInstance(RESOURCE);img.setAbsolutePosition((PageSize.POSTCARD.getWidth() - img.getScaledWidth()) / 2,(PageSize.POSTCARD.getHeight() - img.getScaledHeight()) / 2);document.add(img);document.newPage();// Page 3: the words "Foobar Film Festival"drawRectangle(under, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());;Paragraph p = new Paragraph("Foobar Film Festival", new Font(FontFamily.HELVETICA, 22));p.setAlignment(Element.ALIGN_CENTER);document.add(p);document.newPage();// Page 4: the words "SOLD OUT"drawRectangle(under, PageSize.POSTCARD.getWidth(), PageSize.POSTCARD.getHeight());PdfContentByte over = writer.getDirectContent();over.saveState();float sinus = (float)Math.sin(Math.PI / 60);float cosinus = (float)Math.cos(Math.PI / 60);BaseFont bf = BaseFont.createFont();over.beginText();over.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);over.setLineWidth(1.5f);over.setRGBColorStroke(0xFF, 0x00, 0x00);over.setRGBColorFill(0xFF, 0xFF, 0xFF);over.setFontAndSize(bf, 36);over.setTextMatrix(cosinus, sinus, -sinus, cosinus, 50, 324);over.showText("SOLD OUT");over.setTextMatrix(0, 0);over.endText();over.restoreState();// step 5document.close();}/*** Draws a rectangle* @param content the direct content layer* @param width the width of the rectangle* @param height the height of the rectangle*/public static void drawRectangle(PdfContentByte content, float width, float height) {content.saveState();PdfGState state = new PdfGState();state.setFillOpacity(0.6f);content.setGState(state);content.setRGBColorFill(0xFF, 0xFF, 0xFF);content.setLineWidth(3);content.rectangle(0, 0, width, height);content.fillStroke();content.restoreState();}
}

导入公司信封

从第N页复制页面

6.3 使用PdfStamper添加内容

在绝对位置添加内容

PdfStamper.getOverContent() 类似 getDirectContent()

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.ygsoft.abc.component.cdes.itext.chapter1.HelloWorldLandscape1;
import com.ygsoft.abc.component.cdes.itext.chapter1.HelloWorldLandscape2;public class StampText {/** A resulting PDF file. */public static final String RESULT1= "D:/data/iText/inAction/chapter06/hello1.pdf";/** A resulting PDF file. */public static final String RESULT2= "D:/data/iText/inAction/chapter06/hello2.pdf";/** A resulting PDF file. */public static final String RESULT3= "D:/data/iText/inAction/chapter06/hello3.pdf";/*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args)throws DocumentException, IOException {HelloWorldLandscape1.main(args);HelloWorldLandscape2.main(args);stamp(HelloWorldLandscape1.RESULT, RESULT1);stampIgnoreRotation(HelloWorldLandscape1.RESULT, RESULT2);stamp(HelloWorldLandscape2.RESULT, RESULT3);}/*** Manipulates a PDF file src with the file dest as result* @param src the original PDF* @param dest the resulting PDF* @throws IOException* @throws DocumentException*/public static void stamp(String src, String dest)throws IOException, DocumentException {PdfReader reader = new PdfReader(src);PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));PdfContentByte canvas = stamper.getOverContent(1);ColumnText.showTextAligned(canvas,Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0);stamper.close();}/*** Manipulates a PDF file src with the file dest as result* @param src the original PDF* @param dest the resulting PDF* @throws IOException* @throws DocumentException*/public static void stampIgnoreRotation(String src, String dest)throws IOException, DocumentException {PdfReader reader = new PdfReader(src);PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));stamper.setRotateContents(false);PdfContentByte canvas = stamper.getOverContent(1);ColumnText.showTextAligned(canvas,Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0);stamper.close();}
}

2步创建PDF

第一步,创建文档内容,第二步,添加页码

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;public class TwoPasses {/** The resulting PDF file. */public static final String RESULT= "results/part2/chapter06/page_x_of_y.pdf";/*** Main method.* @param    args    no arguments needed* @throws DocumentException * @throws IOException * @throws SQLException* @throws SQLException*/public static void main(String[] args)throws SQLException, DocumentException, IOException {// FIRST PASS, CREATE THE PDF WITHOUT HEADER// step 1Document document = new Document(PageSize.A4, 36, 36, 54, 36);// step 2ByteArrayOutputStream baos = new ByteArrayOutputStream();PdfWriter.getInstance(document, baos);// step 3document.open();// step 4// PDF文档创建...// step 5document.close();// SECOND PASS, ADD THE HEADER// Create a readerPdfReader reader = new PdfReader(baos.toByteArray());// Create a stamperPdfStamper stamper= new PdfStamper(reader, new FileOutputStream(RESULT));// Loop over the pages and add a header to each pageint n = reader.getNumberOfPages();for (int i = 1; i <= n; i++) {getHeaderTable(i, n).writeSelectedRows(0, -1, 34, 803, stamper.getOverContent(i));}// Close the stamperstamper.close();}/*** Create a header table with page X of Y* @param x the page number* @param y the total number of pages* @return a table that can be used as header*/public static PdfPTable getHeaderTable(int x, int y) {PdfPTable table = new PdfPTable(2);table.setTotalWidth(527);table.setLockedWidth(true);table.getDefaultCell().setFixedHeight(20);table.getDefaultCell().setBorder(Rectangle.BOTTOM);table.addCell("FOOBAR FILMFESTIVAL");table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);table.addCell(String.format("Page %d of %d", x, y));return table;}
}

添加公司信封到一个存在的文档

    /*** Manipulates a PDF file src with the file dest as result* @param src the original PDF* @param stationery a PDF that will be added as background* @param dest the resulting PDF* @throws IOException* @throws DocumentException*/public void manipulatePdf(String src, String stationery, String dest)throws IOException, DocumentException {// Create readersPdfReader reader = new PdfReader(src);PdfReader s_reader = new PdfReader(stationery);// Create the stamperPdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));// Add the stationery to each pagePdfImportedPage page = stamper.getImportedPage(s_reader, 1);int n = reader.getNumberOfPages();PdfContentByte background;for (int i = 1; i <= n; i++) {background = stamper.getUnderContent(i);background.addTemplate(page, 0, 0);}// CLose the stamperstamper.close();}

插入页面到一个存在的文档

填充PDF表单

6.4 使用PdfCopy 拷贝页面

拼接和拆分PDF文档

拼接文档

import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;public class ConcatenateStamp {/** The resulting PDF file. */public static final String RESULT= "results/part2/chapter06/concatenated_stamped.pdf";/*** Main method.* @param args no arguments needed* @throws DocumentException * @throws IOException* @throws SQLException*/public static void main(String[] args)throws IOException, DocumentException, SQLException {// use old examples to create PDFsMovieLinks1.main(args);MovieHistory.main(args);// step 1Document document = new Document();// step 2PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT));// step 3document.open();// step 4// reader for document 1PdfReader reader1 = new PdfReader(MovieLinks1.RESULT);int n1 = reader1.getNumberOfPages();// reader for document 2PdfReader reader2 = new PdfReader(MovieHistory.RESULT);int n2 = reader2.getNumberOfPages();// initializationsPdfImportedPage page;PdfCopy.PageStamp stamp;// Loop over the pages of document 1for (int i = 0; i < n1; ) {page = copy.getImportedPage(reader1, ++i);stamp = copy.createPageStamp(page);// add page numbersColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER,new Phrase(String.format("page %d of %d", i, n1 + n2)),297.5f, 28, 0);stamp.alterContents();copy.addPage(page);}// Loop over the pages of document 2for (int i = 0; i < n2; ) {page = copy.getImportedPage(reader2, ++i);stamp = copy.createPageStamp(page);// add page numbersColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER,new Phrase(String.format("page %d of %d", n1 + i, n1 + n2)),297.5f, 28, 0);stamp.alterContents();copy.addPage(page);}// step 5document.close();}
}

拆分文档

import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;public class Burst {/** Format of the resulting PDF files. */public static final String RESULT= "D:/data/iText/inAction/chapter06/timetable_p%d.pdf";/*** Main method.* @param    args    no arguments needed* @throws DocumentException * @throws IOException*/public static void main(String[] args)throws IOException, DocumentException {// Create a readerPdfReader reader = new PdfReader("D:/data/iText/inAction/chapter03/movie_posters.pdf");// We'll create as many new PDFs as there are pagesDocument document;PdfCopy copy;// loop over all the pages in the original PDFint n = reader.getNumberOfPages();for (int i = 0; i < n; ) {// step 1document = new Document();// step 2copy = new PdfCopy(document,new FileOutputStream(String.format(RESULT, ++i)));// step 3document.open();// step 4copy.addPage(copy.getImportedPage(reader, i));// step 5document.close();}}}

PdfCopy VS PdfSmartCopy

PdfSmartCopy 继承自PdfCopy,其会检查每页添加的冗余对象, 因此可以节省大量磁盘空间或

带宽。这种额外的“智慧”是要付出代价的。PdfSmartCopy 需要更多的内存和时间去拼接文档。

文件大小、带宽优先,选PdfSmartCopy

内存、时间优先,选PdfCopy

拼接表单

相关文章:

iText实战--在现有PDF上工作

6.1 使用PdfReader读取PDF 检索文档和页面信息 D:/data/iText/inAction/chapter03/image_direct.pdf Number of pages: 1 Size of page 1: [0.0,0.0,283.0,416.0] Rotation of page 1: 0 Page size with rotation of page 1: Rectangle: 283.0x416.0 (rot: 0 degrees) Is reb…...

SQL优化--count优化

select count(*) from tb_user ;在之前的测试中&#xff0c;我们发现&#xff0c;如果数据量很大&#xff0c;在执行count操作时&#xff0c;是非常耗时的。 MyISAM 引擎把一个表的总行数存在了磁盘上&#xff0c;因此执行 count(*) 的时候会直接返回这个 数&#xff0c;效率很…...

IDEA下使用Spring MVC

<?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http://ma…...

2022基金从业人员资格管理及后续职业培训 部分答案(自答)

2022基金从业人员资格管理及后续职业培训 区块链在金融交易后处理中的应用私募基金行业典型违法案例分析《证券法》修订情况报告《刑法修正案&#xff08;十一&#xff09;》金融犯罪条款中国结算港股通结算业务介绍商品投资与商品配置价值气候技术&#xff1a;实现双碳目标的技…...

阿里云通义千问向全社会开放,近期将开源更大参数规模大模型

9月13日&#xff0c;阿里云宣布通义千问大模型已首批通过备案&#xff0c;并正式向公众开放&#xff0c;广大用户可登录通义千问官网体验&#xff0c;企业用户可以通过阿里云调用通义千问API。 通义千问在技术创新和行业应用上均位居大模型行业前列。IDC最新的AI大模型评估报告…...

数据结构:二叉查找树

文章目录 二叉查找树一&#xff0c;概述二&#xff0c;添加数据三&#xff0c;删除数据 二叉查找树 一&#xff0c;概述 二叉查找树&#xff0c;也称为二叉搜索树&#xff0c;是一种特殊的二叉树&#xff0c;它或者是一颗空树&#xff0c;或者具有以下性质&#xff1a;对于每…...

Redis的介绍,安装Redis的方式

&#x1f40c;个人主页&#xff1a; &#x1f40c; 叶落闲庭 &#x1f4a8;我的专栏&#xff1a;&#x1f4a8; c语言 数据结构 javaEE 操作系统 石可破也&#xff0c;而不可夺坚&#xff1b;丹可磨也&#xff0c;而不可夺赤。 Redis 初识Redis1.1 认识Redis1.2 安装Redis的方式…...

深入理解CI/CD流程:改变你的开发生命周期

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…...

【React】React入门

目录 一、何为React二、React与传统MVC的关系三、React的特性1、声明式编程①、实现标记地图 2、高效灵活3、组件式开发(Component)①、函数式组件②、类组件&#xff08;有状态组件&#xff09;③、一个组件该有的特点 4、单向式响应的数据流 四、虚拟DOM1、传统DOM更新①、举…...

面相面试知识--Lottery项目

面相面试知识–Lottery项目 1.设计模式 为什么需要设计模式&#xff1f; &#xff08;设计模式是什么&#xff1f;优点有哪些&#xff1f;&#xff09; 设计模式是一套经过验证的有效的软件开发指导思想/解决方案&#xff1b;提高代码的可重用性和可维护性&#xff1b;提高团…...

《Python趣味工具》——自制emoji2(2)

今天&#xff0c;我们将会完成以下2个内容&#xff1a; 绘制静态emoji总结turtle中常用的绘图函数 文章目录 一、绘制静态emoji&#xff1a;:sparkles: 画脸&#xff1a;:sparkles:绘制嘴巴&#xff1a;:sparkles:绘制眼白&#xff1a;绘制眼白-Part1&#xff1a;绘制眼白—pa…...

【面试刷题】——C++四种类型转化

C支持多种类型转换操作&#xff0c;其中包括四种主要类型转换方式&#xff1a; 隐式类型转换&#xff08;Implicit Conversion&#xff09;&#xff1a; 隐式类型转换是自动发生的类型转换&#xff0c;由编译器自动完成。 它用于处理不同数据类型之间的运算&#xff0c;例如将…...

集成Activiti-Modeler流程设计器

集成Activiti-Modeler流程设计器 Activiti Modeler 是 Activiti 官方提供的一款在线流程设计的前端插件&#xff0c;可以方便流程设计与开发人员绘制流程图&#xff0c;保存流程模型&#xff0c;部署至流程定义等等。 1、材料准备 首先我们需要获取activiti-explorer.zip&…...

【深度学习】 Python 和 NumPy 系列教程(十一):NumPy详解:3、数组数学(元素、数组、矩阵级别的各种运算)

目录 一、前言 二、实验环境 三、NumPy 0、多维数组对象&#xff08;ndarray&#xff09; 多维数组的属性 1、创建数组 2、数组操作 3、数组数学 1. 元素级别 a. 直接运算 b. 加法&#xff1a;np.add()函数 c. 减法&#xff1a;np.subtract()函数 d. 乘法&#xf…...

python难题切片处理

边距折叠 Html经常出现的一个外边距折叠,可能有人的不太理解,或者说不知道怎么解决、我们来着重来看下: 当两个div盒子模型连续出现的时候并且同时应用了一个margin外边距,会出现边距重叠的现象: .Div {width:150px; #定义公共的盒子样式 Height:150px; Margin:20p…...

《研发效能(DevOps)工程师(中级)认证》证书查询方式和路径丨IDCF

由国家工业和信息化部教育与考试中心颁发的职业技术证书&#xff0c;也是国内首个《研发效能(DevOps)工程师国家职业技术认证》&#xff0c;IDCF社区作为官方指定培训中心&#xff0c;邀请了多位业界知名专家讲师&#xff08;部分专家讲师名单&#xff1a;王立杰、杜伟忠、陈老…...

NVR添加rtsp流模拟GB28181视频通道

一、海康、大华监控摄像头和硬盘录像机接入GB28181平台配置 1、海康设备接入配置 通过web登录NVR管理系统&#xff0c;进入网络&#xff0c;高级配置界面&#xff0c;填入GB28181相关参数。 将对应项按刚才获取的配置信息填入即可&#xff0c;下面的视频通道的编码ID可以保持…...

浅谈C++|文件篇

引子&#xff1a; 程序运行时产生的数据都属于临时数据&#xff0c;程序一旦运行结束都会被释放通过文件可以将数据持久化。C中对文件操作需要包含头文件< fstream > 。 C提供了丰富的文件操作功能&#xff0c;你可以使用标准库中的fstream库来进行文件的读取、写入和定位…...

C++ QT qml 学习之 做个登录界面

最近在学习QT&#xff0c;也初探到qml 做ui 的灵活性与强大&#xff0c;于是手痒痒&#xff0c;做个demo 记录下学习成果 主要内容是如何自己编写一个按钮以及qml多窗口。 参考WX桌面版&#xff0c;做一个登录界面&#xff0c;这里面按钮是写的一个组合控件&#xff0c;有 按…...

LLM 06-大模型架构

LLM 06-大模型架构 6.1 大模型之模型概括 语言模型的一开始就可以被看做是一个黑箱&#xff0c;当前大规模语言模型的能力在于给定一个基于自身需求的prompt就可以生成符合需求的结果。形式可以表达为&#xff1a; p r o m p t ⇝ c o m p l e t i o n prompt \leadsto compl…...

Flask RESTful 示例

目录 1. 环境准备2. 安装依赖3. 修改main.py4. 运行应用5. API使用示例获取所有任务获取单个任务创建新任务更新任务删除任务 中文乱码问题&#xff1a; 下面创建一个简单的Flask RESTful API示例。首先&#xff0c;我们需要创建环境&#xff0c;安装必要的依赖&#xff0c;然后…...

IGP(Interior Gateway Protocol,内部网关协议)

IGP&#xff08;Interior Gateway Protocol&#xff0c;内部网关协议&#xff09; 是一种用于在一个自治系统&#xff08;AS&#xff09;内部传递路由信息的路由协议&#xff0c;主要用于在一个组织或机构的内部网络中决定数据包的最佳路径。与用于自治系统之间通信的 EGP&…...

CMake 从 GitHub 下载第三方库并使用

有时我们希望直接使用 GitHub 上的开源库,而不想手动下载、编译和安装。 可以利用 CMake 提供的 FetchContent 模块来实现自动下载、构建和链接第三方库。 FetchContent 命令官方文档✅ 示例代码 我们将以 fmt 这个流行的格式化库为例,演示如何: 使用 FetchContent 从 GitH…...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)

参考官方文档&#xff1a;https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java&#xff08;供 Kotlin 使用&#xff09; 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

Unity | AmplifyShaderEditor插件基础(第七集:平面波动shader)

目录 一、&#x1f44b;&#x1f3fb;前言 二、&#x1f608;sinx波动的基本原理 三、&#x1f608;波动起来 1.sinx节点介绍 2.vertexPosition 3.集成Vector3 a.节点Append b.连起来 4.波动起来 a.波动的原理 b.时间节点 c.sinx的处理 四、&#x1f30a;波动优化…...

PAN/FPN

import torch import torch.nn as nn import torch.nn.functional as F import mathclass LowResQueryHighResKVAttention(nn.Module):"""方案 1: 低分辨率特征 (Query) 查询高分辨率特征 (Key, Value).输出分辨率与低分辨率输入相同。"""def __…...

GO协程(Goroutine)问题总结

在使用Go语言来编写代码时&#xff0c;遇到的一些问题总结一下 [参考文档]&#xff1a;https://www.topgoer.com/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/goroutine.html 1. main()函数默认的Goroutine 场景再现&#xff1a; 今天在看到这个教程的时候&#xff0c;在自己的电…...

【Android】Android 开发 ADB 常用指令

查看当前连接的设备 adb devices 连接设备 adb connect 设备IP 断开已连接的设备 adb disconnect 设备IP 安装应用 adb install 安装包的路径 卸载应用 adb uninstall 应用包名 查看已安装的应用包名 adb shell pm list packages 查看已安装的第三方应用包名 adb shell pm list…...

Rust 开发环境搭建

环境搭建 1、开发工具RustRover 或者vs code 2、Cygwin64 安装 https://cygwin.com/install.html 在工具终端执行&#xff1a; rustup toolchain install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu ​ 2、Hello World fn main() { println…...

c# 局部函数 定义、功能与示例

C# 局部函数&#xff1a;定义、功能与示例 1. 定义与功能 局部函数&#xff08;Local Function&#xff09;是嵌套在另一个方法内部的私有方法&#xff0c;仅在包含它的方法内可见。 • 作用&#xff1a;封装仅用于当前方法的逻辑&#xff0c;避免污染类作用域&#xff0c;提升…...