在.NET中没有很好操作pdf的类库,如果你需要对pdf进行编辑,加密,模板打印等等都可以选择使用ITextSharp来实现。

第一步:可以点击这里下载,新版本的插件升级和之前对比主要做了这几项重大改变

1.初始化对汉字的支持

2.对页眉页脚的加载形式

第二步:制作pdf模板

可以下载Adobe Acrobat DC等任意一款pdf编辑工具,视图——工具——准备表单,可以在需要赋值的地方放上一个文本框,可以把名称修改为有意义的名称,后面在赋值时要用到。

第三步:建项目引入各个操作类

介于前段时间项目所需特意把ITextSharp进行了二次封装,使我们对pdf操作起来更加方便。

列一下各文件的作用:

CanvasRectangle.cs对Rectangle对象的基类支持,可以灵活定义一个Rectangle。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{/// <summary>/// 画布对象/// </summary>public class CanvasRectangle{#region CanvasRectangle属性public float StartX { get; set; }public float StartY { get; set; }public float RectWidth { get; set; }public float RectHeight { get; set; }#endregion#region 初始化Rectangle/// <summary>/// 提供rectangle信息/// </summary>/// <param name="startX">起点X坐标</param>/// <param name="startY">起点Y坐标</param>/// <param name="rectWidth">指定rectangle宽</param>/// <param name="rectHeight">指定rectangle高</param>public CanvasRectangle(float startX, float startY, float rectWidth, float rectHeight){this.StartX = startX;this.StartY = startY;this.RectWidth = rectWidth;this.RectHeight = rectHeight;}#endregion#region 获取图形缩放百分比/// <summary>/// 获取指定宽高压缩后的百分比/// </summary>/// <param name="width">目标宽</param>/// <param name="height">目标高</param>/// <param name="containerRect">原始对象</param>/// <returns>目标与原始对象百分比</returns>public static float GetPercentage(float width, float height, CanvasRectangle containerRect){float percentage = 0;if (height > width){percentage = containerRect.RectHeight / height;if (width * percentage > containerRect.RectWidth){percentage = containerRect.RectWidth / width;}}else{percentage = containerRect.RectWidth / width;if (height * percentage > containerRect.RectHeight){percentage = containerRect.RectHeight / height;}}return percentage;}#endregion}}CanvasRectangle.cs

PdfBase.cs主要继承PdfPageEventHelper,并实现IPdfPageEvent接口的具体实现,其实也是在pdf的加载,分页等事件中可以重写一些具体操作。

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{public class PdfBase : PdfPageEventHelper  {#region 属性  private String _fontFilePathForHeaderFooter = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SIMHEI.TTF");  /// <summary>  /// 页眉/页脚所用的字体  /// </summary>  public String FontFilePathForHeaderFooter  {  get  {  return _fontFilePathForHeaderFooter;  }  set  {  _fontFilePathForHeaderFooter = value;  }  }  private String _fontFilePathForBody = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SIMSUN.TTC,1");  /// <summary>  /// 正文内容所用的字体  /// </summary>  public String FontFilePathForBody  {  get { return _fontFilePathForBody; }  set { _fontFilePathForBody = value; }  }  private PdfPTable _header;  /// <summary>  /// 页眉  /// </summary>  public PdfPTable Header  {  get { return _header; }  private set { _header = value; }  }  private PdfPTable _footer;  /// <summary>  /// 页脚  /// </summary>  public PdfPTable Footer  {  get { return _footer; }  private set { _footer = value; }  }  private BaseFont _baseFontForHeaderFooter;  /// <summary>  /// 页眉页脚所用的字体  /// </summary>  public BaseFont BaseFontForHeaderFooter  {  get { return _baseFontForHeaderFooter; }  set { _baseFontForHeaderFooter = value; }  }  private BaseFont _baseFontForBody;  /// <summary>  /// 正文所用的字体  /// </summary>  public BaseFont BaseFontForBody  {  get { return _baseFontForBody; }  set { _baseFontForBody = value; }  }  private Document _document;  /// <summary>  /// PDF的Document  /// </summary>  public Document Document  {  get { return _document; }  private set { _document = value; }  }  #endregion  public override void OnOpenDocument(PdfWriter writer, Document document)  {  try  {  BaseFontForHeaderFooter = BaseFont.CreateFont(FontFilePathForHeaderFooter, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);  BaseFontForBody = BaseFont.CreateFont(FontFilePathForBody, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);document.Add(new Phrase("\n\n"));Document = document;  }  catch (DocumentException de)  {  }  catch (System.IO.IOException ioe)  {  }  }  #region GenerateHeader  /// <summary>  /// 生成页眉  /// </summary>  /// <param name="writer"></param>  /// <returns></returns>  public virtual PdfPTable GenerateHeader(iTextSharp.text.pdf.PdfWriter writer)  {  return null;  }  #endregion  #region GenerateFooter  /// <summary>  /// 生成页脚  /// </summary>  /// <param name="writer"></param>  /// <returns></returns>  public virtual PdfPTable GenerateFooter(iTextSharp.text.pdf.PdfWriter writer)  {  return null;  }  #endregion  public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)  {base.OnEndPage(writer, document);//输出页眉  Header = GenerateHeader(writer);  Header.TotalWidth = document.PageSize.Width - 20f;  ///调用PdfTable的WriteSelectedRows方法。该方法以第一个参数作为开始行写入。  ///第二个参数-1表示没有结束行,并且包含所写的所有行。  ///第三个参数和第四个参数是开始写入的坐标x和y.  Header.WriteSelectedRows(0, -1, 10, document.PageSize.Height - 20, writer.DirectContent);  //输出页脚  Footer = GenerateFooter(writer);  Footer.TotalWidth = document.PageSize.Width - 20f;  Footer.WriteSelectedRows(0, -1, 10, document.PageSize.GetBottom(50), writer.DirectContent);  }  }
}PdfBase.cs

PdfImage.cs对图像文件的操作

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{/// <summary>/// pdf图片操作类/// </summary>public class PdfImage{#region PdfImage属性/// <summary>/// 图片URL地址/// </summary>public string ImageUrl { get; set; }/// <summary>/// 图片域宽/// </summary>public float FitWidth { get; set; }/// <summary>/// 图片域高/// </summary>public float FitHeight { get; set; }/// <summary>/// 绝对X坐标/// </summary>public float AbsoluteX { get; set; }/// <summary>/// 绝对Y坐标/// </summary>public float AbsoluteY { get; set; }/// <summary>/// Img内容/// </summary>public byte[] ImgBytes { get; set; }/// <summary>/// 是否缩放/// </summary>public bool ScaleParent { get; set; }/// <summary>/// 画布对象/// </summary>public CanvasRectangle ContainerRect { get; set; }#endregion#region  PdfImage构造/// <summary>/// 网络图片写入/// </summary>/// <param name="imageUrl">图片URL地址</param>/// <param name="fitWidth"></param>/// <param name="fitHeight"></param>/// <param name="absolutX"></param>/// <param name="absoluteY"></param>/// <param name="scaleParent"></param>public PdfImage(string imageUrl, float fitWidth, float fitHeight, float absolutX, float absoluteY, bool scaleParent){this.ImageUrl = imageUrl;this.FitWidth = fitWidth;this.FitHeight = fitHeight;this.AbsoluteX = absolutX;this.AbsoluteY = absoluteY;this.ScaleParent = scaleParent;}/// <summary>/// 本地文件写入/// </summary>///  <param name="imageUrl">图片URL地址</param>/// <param name="fitWidth"></param>/// <param name="fitHeight"></param>/// <param name="absolutX"></param>/// <param name="absoluteY"></param>/// <param name="scaleParent"></param>/// <param name="imgBytes"></param>public PdfImage(string imageUrl, float fitWidth, float fitHeight, float absolutX, float absoluteY, bool scaleParent, byte[] imgBytes){this.ImageUrl = imageUrl;this.FitWidth = fitWidth;this.FitHeight = fitHeight;this.AbsoluteX = absolutX;this.AbsoluteY = absoluteY;this.ScaleParent = scaleParent;this.ImgBytes = imgBytes;}#endregion#region 指定pdf模板文件添加图片/// <summary>/// 指定pdf模板文件添加图片/// </summary>/// <param name="tempFilePath"></param>/// <param name="createdPdfPath"></param>/// <param name="pdfImages"></param>public void PutImages(string tempFilePath, string createdPdfPath, List<PdfImage> pdfImages){PdfReader pdfReader = null;PdfStamper pdfStamper = null;try{pdfReader = new PdfReader(tempFilePath);pdfStamper = new PdfStamper(pdfReader, new FileStream(createdPdfPath, FileMode.OpenOrCreate));var pdfContentByte = pdfStamper.GetOverContent(1);//获取PDF指定页面内容foreach (var pdfImage in pdfImages){Uri uri = null;Image img = null;var imageUrl = pdfImage.ImageUrl;//如果使用网络路径则先将图片转化位绝对路径if (imageUrl.StartsWith("http")){//var absolutePath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(".."), imageUrl);  var absolutePath = System.Web.HttpContext.Current.Server.MapPath("..") + imageUrl;uri = new Uri(absolutePath);img = Image.GetInstance(uri);}else{//如果直接使用图片文件则直接创建iTextSharp的Image对象if (pdfImage.ImgBytes != null){img = Image.GetInstance(new MemoryStream(pdfImage.ImgBytes));}}if (img != null){if (pdfImage.ScaleParent){var containerRect = pdfImage.ContainerRect;float percentage = 0.0f;percentage =CanvasRectangle.GetPercentage(img.Width, img.Height, containerRect);img.ScalePercent(percentage * 100);pdfImage.AbsoluteX = (containerRect.RectWidth - img.Width * percentage) / 2 + containerRect.StartX;pdfImage.AbsoluteY = (containerRect.RectHeight - img.Height * percentage) / 2 + containerRect.StartY;}else{img.ScaleToFit(pdfImage.FitWidth, pdfImage.FitHeight);}img.SetAbsolutePosition(pdfImage.AbsoluteX, pdfImage.AbsoluteY);pdfContentByte.AddImage(img);}}pdfStamper.FormFlattening = true;}catch (Exception ex){throw ex;}finally{if (pdfStamper != null){pdfStamper.Close();}if (pdfReader != null){pdfReader.Close();}pdfStamper = null;pdfReader = null;}}#endregion}
}PdfImage.cs

PdfPageMerge.cs对pdf文件及文件、各种文件格式文件内容进行合并。

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{public class PdfPageMerge{private PdfWriter pw;private PdfReader reader;       private Document document;private PdfContentByte cb;private PdfImportedPage newPage;private FileStream fs;/// <summary>/// 通过输出文件来构建合并管理,合并到新增文件中,合并完成后调用FinishedMerge方法/// </summary>/// <param name="sOutFiles">输出文件</param>public PdfPageMerge(string sOutFiles){document = new Document(PageSize.A4);fs=new FileStream(sOutFiles, FileMode.Create);pw = PdfWriter.GetInstance(document, fs);document.Open();cb = pw.DirectContent;}       /// <summary>/// 通过文件流来合并文件,合并到当前的可写流中,合并完成后调用FinishedMerge方法/// </summary>/// <param name="sm"></param>public PdfPageMerge(Stream sm){document = new Document();pw = PdfWriter.GetInstance(document, sm);            document.Open();cb = pw.DirectContent;}/// <summary>/// 合并文件/// </summary>/// <param name="sFiles">需要合并的文件路径名称</param>/// <returns></returns>public bool MergeFile(string sFiles){reader = new PdfReader(sFiles);           {int iPageNum = reader.NumberOfPages;for (int j = 1; j <= iPageNum; j++){newPage = pw.GetImportedPage(reader, j);//Rectangle r = reader.GetPageSize(j);Rectangle r = reader.GetPageSizeWithRotation(j);document.SetPageSize(r);cb.AddTemplate(newPage, 0, 0);document.NewPage();}}reader.Close();            return true;}/// <summary>/// 通过字节数据合并文件/// </summary>/// <param name="pdfIn">PDF字节数据</param>/// <returns></returns>public bool MergeFile(byte[] pdfIn){reader = new PdfReader(pdfIn);{int iPageNum = reader.NumberOfPages;for (int j = 1; j <= iPageNum; j++){newPage = pw.GetImportedPage(reader, j);Rectangle r = reader.GetPageSize(j);document.SetPageSize(r);document.NewPage();cb.AddTemplate(newPage, 0, 0);}}reader.Close();return true;}/// <summary>/// 通过PDF文件流合并文件/// </summary>/// <param name="pdfStream">PDF文件流</param>/// <returns></returns>public bool MergeFile(Stream pdfStream){reader = new PdfReader(pdfStream);{int iPageNum = reader.NumberOfPages;for (int j = 1; j <= iPageNum; j++){newPage = pw.GetImportedPage(reader, j);Rectangle r = reader.GetPageSize(j);document.SetPageSize(r);document.NewPage();cb.AddTemplate(newPage, 0, 0);}}reader.Close();return true;}/// <summary>/// 通过网络地址来合并文件/// </summary>/// <param name="pdfUrl">需要合并的PDF的网络路径</param>/// <returns></returns>public bool MergeFile(Uri pdfUrl){reader = new PdfReader(pdfUrl);{int iPageNum = reader.NumberOfPages;for (int j = 1; j <= iPageNum; j++){newPage = pw.GetImportedPage(reader, j);Rectangle r = reader.GetPageSize(j);document.SetPageSize(r);document.NewPage();cb.AddTemplate(newPage, 0, 0);}}reader.Close();return true;}/// <summary>/// 完成合并/// </summary>public void FinishedMerge(){try{if (reader != null){reader.Close();}if (pw != null){pw.Flush();pw.Close();}if (fs != null){fs.Flush();fs.Close();}if (document.IsOpen()){document.Close();}}catch{}}public static string AddCommentsToFile(string fileName,string outfilepath, string userComments, PdfPTable newTable){string outputFileName = outfilepath;//Step 1: Create a Docuement-ObjectDocument document = new Document();try{//Step 2: we create a writer that listens to the documentPdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outputFileName, FileMode.Create));//Step 3: Open the documentdocument.Open();PdfContentByte cb = writer.DirectContent;//The current file pathstring filename = fileName;// we create a reader for the documentPdfReader reader = new PdfReader(filename);for (int pageNumber = 1; pageNumber < reader.NumberOfPages + 1; pageNumber++){document.SetPageSize(reader.GetPageSizeWithRotation(1));document.NewPage();//Insert to Destination on the first pageif (pageNumber == 1){Chunk fileRef = new Chunk(" ");fileRef.SetLocalDestination(filename);document.Add(fileRef);}PdfImportedPage page = writer.GetImportedPage(reader, pageNumber);int rotation = reader.GetPageRotation(pageNumber);if (rotation == 90 || rotation == 270){cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(pageNumber).Height);}else{cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);}}// Add a new page to the pdf filedocument.NewPage();Paragraph paragraph = new Paragraph();Font titleFont = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 15, iTextSharp.text.Font.BOLD, BaseColor.BLACK);Chunk titleChunk = new Chunk("Comments", titleFont);paragraph.Add(titleChunk);document.Add(paragraph);paragraph = new Paragraph();Font textFont = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);Chunk textChunk = new Chunk(userComments, textFont);paragraph.Add(textChunk);document.Add(paragraph);document.Add(newTable);}catch (Exception e){throw e;}finally{document.Close();}return outputFileName;}}
}PdfPageMerge.cs

PdfTable.cs对表格插入做支持,可以在表格插入时动态生成新页并可以为每页插入页眉页脚

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;namespace PDFReport
{/// <summary>/// Pdf表格操作类/// </summary>public class PdfTable:PdfBase{/// <summary>/// 向PDF中动态插入表格,表格内容按照htmltable标记格式插入/// </summary>/// <param name="pdfTemplate">pdf模板路径</param>/// <param name="tempFilePath">pdf导出路径</param>/// <param name="parameters">table标签</param>public void PutTable(string pdfTemplate, string tempFilePath, string parameter){Document doc = new Document();try{if (File.Exists(tempFilePath)){File.Delete(tempFilePath);}doc = new Document(PageSize.LETTER);FileStream temFs = new FileStream(tempFilePath, FileMode.OpenOrCreate);PdfWriter PWriter = PdfWriter.GetInstance(doc,temFs);PdfTable pagebase = new PdfTable();PWriter.PageEvent = pagebase;//添加页眉页脚BaseFont bf1 = BaseFont.CreateFont("C:\\Windows\\Fonts\\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);iTextSharp.text.Font CellFont = new iTextSharp.text.Font(bf1, 12);doc.Open();   PdfContentByte cb = PWriter.DirectContent;PdfReader reader = new PdfReader(pdfTemplate);for (int pageNumber = 1; pageNumber < reader.NumberOfPages+1 ; pageNumber++){doc.SetPageSize(reader.GetPageSizeWithRotation(1));PdfImportedPage page = PWriter.GetImportedPage(reader, pageNumber);int rotation = reader.GetPageRotation(pageNumber);cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);doc.NewPage();                         }XmlDocument xmldoc = new XmlDocument();xmldoc.LoadXml(parameter);XmlNodeList xnlTable = xmldoc.SelectNodes("table");if (xnlTable.Count > 0){foreach (XmlNode xn in xnlTable){//添加表格与正文之间间距doc.Add(new Phrase("\n\n"));// 由html标记和属性解析表格样式var xmltr = xn.SelectNodes("tr");foreach (XmlNode xntr in xmltr){var xmltd = xntr.SelectNodes("td");PdfPTable newTable = new PdfPTable(xmltd.Count);foreach (XmlNode xntd in xmltd){PdfPCell newCell = new PdfPCell(new Paragraph(1, xntd.InnerText, CellFont));newTable.AddCell(newCell);//表格添加内容var tdStyle = xntd.Attributes["style"];//获取单元格样式if (tdStyle != null){string[] styles = tdStyle.Value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);Dictionary<string, string> dicStyle = new Dictionary<string, string>();foreach (string strpar in styles){ string[] keyvalue=strpar.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);dicStyle.Add(keyvalue[0], keyvalue[1]);}//设置单元格宽度if (dicStyle.Select(sty => sty.Key.ToLower().Equals("width")).Count() > 0){newCell.Width =float.Parse(dicStyle["width"]);}//设置单元格高度if (dicStyle.Select(sty => sty.Key.ToLower().Equals("height")).Count() > 0){//newCell.Height = float.Parse(dicStyle["height"]);}}}doc.Add(newTable);}}                }doc.Close();temFs.Close();PWriter.Close();}catch (Exception ex){throw ex;}finally{doc.Close();}}#region GenerateHeader/// <summary>  /// 生成页眉  /// </summary>  /// <param name="writer"></param>  /// <returns></returns>  public override PdfPTable GenerateHeader(iTextSharp.text.pdf.PdfWriter writer){BaseFont baseFont = BaseFontForHeaderFooter;iTextSharp.text.Font font_logo = new iTextSharp.text.Font(baseFont, 18, iTextSharp.text.Font.BOLD);iTextSharp.text.Font font_header1 = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.BOLD);iTextSharp.text.Font font_header2 = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.BOLD);iTextSharp.text.Font font_headerContent = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.NORMAL);float[] widths = new float[] { 355, 50, 90, 15, 20, 15 };PdfPTable header = new PdfPTable(widths);PdfPCell cell = new PdfPCell();cell.BorderWidthBottom = 2;cell.BorderWidthLeft = 2;cell.BorderWidthTop = 2;cell.BorderWidthRight = 2;cell.FixedHeight = 35;cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_LEFT);//Image img = Image.GetInstance("http://simg.instrument.com.cn/home/20141224/images/200_50logo.gif");//img.ScaleToFit(100f, 20f);//cell.Image = img;cell.Phrase = new Phrase("LOGO", font_logo);cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_CENTER;cell.PaddingTop = -1;header.AddCell(cell);//cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_LEFT);//cell.Phrase = new Paragraph("PDF报表", font_header1);//header.AddCell(cell);cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);cell.Phrase = new Paragraph("日期:", font_header2);header.AddCell(cell);cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_LEFT);cell.Phrase = new Paragraph(DateTime.Now.ToString("yyyy-MM-dd"), font_headerContent);header.AddCell(cell);cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);cell.Phrase = new Paragraph("第", font_header2);header.AddCell(cell);cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_CENTER);cell.Phrase = new Paragraph(writer.PageNumber.ToString(), font_headerContent);header.AddCell(cell);cell = GenerateOnlyBottomBorderCell(2, iTextSharp.text.Element.ALIGN_RIGHT);cell.Phrase = new Paragraph("页", font_header2);header.AddCell(cell);return header;}#region /// <summary>  /// 生成只有底边的cell  /// </summary>  /// <param name="bottomBorder"></param>  /// <param name="horizontalAlignment">水平对齐方式<see cref="iTextSharp.text.Element"/></param>  /// <returns></returns>  private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder,int horizontalAlignment){PdfPCell cell = GenerateOnlyBottomBorderCell(bottomBorder, horizontalAlignment, iTextSharp.text.Element.ALIGN_BOTTOM);cell.PaddingBottom = 5;return cell;}/// <summary>  /// 生成只有底边的cell  /// </summary>  /// <param name="bottomBorder"></param>  /// <param name="horizontalAlignment">水平对齐方式<see cref="iTextSharp.text.Element"/></param>  /// <param name="verticalAlignment">垂直对齐方式<see cref="iTextSharp.text.Element"/</param>  /// <returns></returns>  private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder,int horizontalAlignment,int verticalAlignment){PdfPCell cell = GenerateOnlyBottomBorderCell(bottomBorder);cell.HorizontalAlignment = horizontalAlignment;cell.VerticalAlignment = verticalAlignment; ;return cell;}/// <summary>  /// 生成只有底边的cell  /// </summary>  /// <param name="bottomBorder"></param>  /// <returns></returns>  private PdfPCell GenerateOnlyBottomBorderCell(int bottomBorder){PdfPCell cell = new PdfPCell();cell.BorderWidthBottom = 2;cell.BorderWidthLeft = 0;cell.BorderWidthTop = 0;cell.BorderWidthRight = 0;return cell;}#endregion#endregion  #region GenerateFooterpublic override PdfPTable GenerateFooter(iTextSharp.text.pdf.PdfWriter writer){BaseFont baseFont = BaseFontForHeaderFooter;iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 10, iTextSharp.text.Font.NORMAL);PdfPTable footer = new PdfPTable(new float[]{1,1,2,1});AddFooterCell(footer, "电话:010-51654077-8039", font);AddFooterCell(footer, "传真:010-82051730", font);AddFooterCell(footer, "电子邮件:yangdd@instrument.com.cn", font);AddFooterCell(footer, "联系人:杨丹丹", font);return footer;}private void AddFooterCell(PdfPTable foot, String text, iTextSharp.text.Font font){PdfPCell cell = new PdfPCell();cell.BorderWidthTop = 2;cell.BorderWidthRight = 0;cell.BorderWidthBottom = 0;cell.BorderWidthLeft = 0;cell.Phrase = new Phrase(text, font);cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;foot.AddCell(cell);}#endregion  }
}PdfTable.cs

PdfText.cs对pdf模板上的表单进行赋值,并生成新的pdf

using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{/// <summary>/// pdf文本域操作类/// </summary>public class PdfText{#region  pdf模板文本域复制/// <summary>/// 指定pdf模板为其文本域赋值/// </summary>/// <param name="pdfTemplate">pdf模板路径</param>/// <param name="tempFilePath">pdf导出路径</param>/// <param name="parameters">pdf模板域键值</param>public void PutText(string pdfTemplate, string tempFilePath, Dictionary<string, string> parameters){PdfReader pdfReader = null;PdfStamper pdfStamper = null;try{if (File.Exists(tempFilePath)){File.Delete(tempFilePath);}pdfReader = new PdfReader(pdfTemplate);pdfStamper = new PdfStamper(pdfReader, new FileStream(tempFilePath, FileMode.OpenOrCreate));AcroFields pdfFormFields = pdfStamper.AcroFields;pdfStamper.FormFlattening = true;BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);BaseFont simheiBase = BaseFont.CreateFont(@"C:\Windows\Fonts\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);pdfFormFields.AddSubstitutionFont(simheiBase);foreach (KeyValuePair<string, string> parameter in parameters){if (pdfFormFields.Fields[parameter.Key] != null){pdfFormFields.SetField(parameter.Key, parameter.Value);}}}catch (Exception ex){throw ex;}finally{pdfStamper.Close();pdfReader.Close();pdfStamper = null;pdfReader = null;}}#endregion}
}PdfText.cs

PdfWatermark.cs可以为pdf文档添加文字和图片水印

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace PDFReport
{/// <summary>/// pdf水银操作/// </summary>public class PdfWatermark{#region 添加普通偏转角度文字水印/// <summary>/// 添加普通偏转角度文字水印/// </summary>/// <param name="inputfilepath">需要添加水印的pdf文件</param>/// <param name="outputfilepath">添加水印后输出的pdf文件</param>/// <param name="waterMarkName">水印内容</param>public  void setWatermark(string inputfilepath, string outputfilepath, string waterMarkName){PdfReader pdfReader = null;PdfStamper pdfStamper = null;try{if (File.Exists(outputfilepath)){File.Delete(outputfilepath);}pdfReader = new PdfReader(inputfilepath);pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.OpenOrCreate));int total = pdfReader.NumberOfPages + 1;iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);float width = psize.Width;float height = psize.Height;PdfContentByte content;BaseFont font = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);PdfGState gs = new PdfGState();for (int i = 1; i < total; i++){content = pdfStamper.GetOverContent(i);//在内容上方加水印//content = pdfStamper.GetUnderContent(i);//在内容下方加水印//透明度gs.FillOpacity = 0.3f;content.SetGState(gs);//content.SetGrayFill(0.3f);//开始写入文本content.BeginText();content.SetColorFill(BaseColor.LIGHT_GRAY);content.SetFontAndSize(font, 100);content.SetTextMatrix(0, 0);content.ShowTextAligned(Element.ALIGN_CENTER, waterMarkName, width / 2 - 50, height / 2 - 50, 55);//content.SetColorFill(BaseColor.BLACK);//content.SetFontAndSize(font, 8);//content.ShowTextAligned(Element.ALIGN_CENTER, waterMarkName, 0, 0, 0);content.EndText();}}catch (Exception ex){throw ex;}finally{if (pdfStamper != null)pdfStamper.Close();if (pdfReader != null)pdfReader.Close();}}#endregion#region 添加倾斜水印,并加密文档/// <summary>/// 添加倾斜水印,并加密文档/// </summary>/// <param name="inputfilepath">需要添加水印的pdf文件</param>/// <param name="outputfilepath">添加水印后输出的pdf文件</param>/// <param name="waterMarkName">水印内容</param>/// <param name="userPassWord">用户密码</param>/// <param name="ownerPassWord">作者密码</param>/// <param name="permission">许可等级</param>public  void setWatermark(string inputfilepath, string outputfilepath, string waterMarkName, string userPassWord, string ownerPassWord, int permission){PdfReader pdfReader = null;PdfStamper pdfStamper = null;try{pdfReader = new PdfReader(inputfilepath);pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.OpenOrCreate));// 设置密码   //pdfStamper.SetEncryption(false,userPassWord, ownerPassWord, permission); int total = pdfReader.NumberOfPages + 1;PdfContentByte content;BaseFont font = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);PdfGState gs = new PdfGState();gs.FillOpacity = 0.2f;//透明度int j = waterMarkName.Length;char c;int rise = 0;for (int i = 1; i < total; i++){rise = 500;content = pdfStamper.GetOverContent(i);//在内容上方加水印//content = pdfStamper.GetUnderContent(i);//在内容下方加水印content.BeginText();content.SetColorFill(BaseColor.DARK_GRAY);content.SetFontAndSize(font, 50);// 设置水印文字字体倾斜 开始 if (j >= 15){content.SetTextMatrix(200, 120);for (int k = 0; k < j; k++){content.SetTextRise(rise);c = waterMarkName[k];content.ShowText(c + "");rise -= 20;}}else{content.SetTextMatrix(180, 100);for (int k = 0; k < j; k++){content.SetTextRise(rise);c = waterMarkName[k];content.ShowText(c + "");rise -= 18;}}// 字体设置结束 content.EndText();// 画一个圆 //content.Ellipse(250, 450, 350, 550);//content.SetLineWidth(1f);//content.Stroke(); }}catch (Exception ex){throw ex;}finally{if (pdfStamper != null)pdfStamper.Close();if (pdfReader != null)pdfReader.Close();}}#endregion#region 加图片水印/// <summary>/// 加图片水印/// </summary>/// <param name="inputfilepath"></param>/// <param name="outputfilepath"></param>/// <param name="ModelPicName"></param>/// <param name="top"></param>/// <param name="left"></param>/// <returns></returns>public  bool PDFWatermark(string inputfilepath, string outputfilepath, string ModelPicName, float top, float left){PdfReader pdfReader = null;PdfStamper pdfStamper = null;try{pdfReader = new PdfReader(inputfilepath);int numberOfPages = pdfReader.NumberOfPages;iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);float width = psize.Width;float height = psize.Height;pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.OpenOrCreate));PdfContentByte waterMarkContent;iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(ModelPicName);image.GrayFill = 80;//透明度,灰色填充//image.Rotation = 40;//旋转image.RotationDegrees = 40;//旋转角度//水印的位置 if (left < 0){left = width / 2 - image.Width + left;}//image.SetAbsolutePosition(left, (height - image.Height) - top);image.SetAbsolutePosition(left, (height / 2 - image.Height) - top);//每一页加水印,也可以设置某一页加水印 for (int i = 1; i <= numberOfPages; i++){waterMarkContent = pdfStamper.GetUnderContent(i);//内容下层加水印//waterMarkContent = pdfStamper.GetOverContent(i);//内容上层加水印waterMarkContent.AddImage(image);}//strMsg = "success";return true;}catch (Exception ex){throw ex;}finally{if (pdfStamper != null)pdfStamper.Close();if (pdfReader != null)pdfReader.Close();}}#endregion}
}PdfWatermark.cs

PdfPage.aspx.cs页面调用

using PDFReport;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace CreatePDF
{public partial class PdfPage : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}#region  默认文档protected void defaultpdf_Click(object sender, EventArgs e){iframepdf.Attributes["src"] = "../PDFTemplate/pdfTemplate.pdf";}#endregion#region 文字域protected void CreatePdf_Click(object sender, EventArgs e){string pdfTemplate = Server.MapPath("~/PDFTemplate/pdfTemplate.pdf");string newpdf = Server.MapPath("~/PDFTemplate/newpdf.pdf");//追加文本##########Dictionary<string, string> dicPra = new Dictionary<string, string>();dicPra.Add("HTjiafang", "北京美嘉生物科技有限公司111111");dicPra.Add("Total", "1370000000000000");dicPra.Add("TotalDaXie", "壹万叁仟柒佰元整");dicPra.Add("Date", "2017年12月12日前付款3000元,2018年1月10日前付余款10700元");new PdfText().PutText(pdfTemplate, newpdf, dicPra);iframepdf.Attributes["src"]="../PDFTemplate/newpdf.pdf";//Response.Write("<script> alert('已生成pdf');</script>");}#endregion#region 普通水印protected void WaterMark_Click(object sender, EventArgs e){string pdfTemplate = Server.MapPath("~/PDFTemplate/pdfTemplate.pdf");string newpdf = Server.MapPath("~/PDFTemplate/newpdf1.pdf");//添加水印############new PdfWatermark().setWatermark(pdfTemplate, newpdf, "仪器信息网");iframepdf.Attributes["src"] = "../PDFTemplate/newpdf1.pdf";//Response.Write("<script> alert('已生成pdf');</script>");}#endregion#region 图片水印protected void WaterMarkPic_Click(object sender, EventArgs e){string pdfTemplate = Server.MapPath("~/PDFTemplate/pdfTemplate.pdf");string newpdf = Server.MapPath("~/PDFTemplate/newpdf2.pdf");//添加图片水印############new PdfWatermark().PDFWatermark(pdfTemplate, newpdf, Server.MapPath("~/Images/200_50logo.gif"), 0, 0);iframepdf.Attributes["src"] = "../PDFTemplate/newpdf2.pdf";//Response.Write("<script> alert('已生成pdf');</script>");}#endregion#region 添加印章protected void PdfImg_Click(object sender, EventArgs e){string pdfTemplate = Server.MapPath("~/PDFTemplate/pdfTemplate.pdf");string newpdf = Server.MapPath("~/PDFTemplate/newpdf3.pdf");//追加图片#############FileStream fs = new FileStream(Server.MapPath("~/Images/yinzhang.png"), FileMode.Open);byte[] byData = new byte[fs.Length];fs.Read(byData, 0, byData.Length);fs.Close();PdfImage pdfimg = new PdfImage("", 100f, 100f, 400f, 470f, false, byData);List<PdfImage> listimg = new List<PdfImage>();listimg.Add(pdfimg);pdfimg.PutImages(pdfTemplate, newpdf, listimg);iframepdf.Attributes["src"] = "../PDFTemplate/newpdf3.pdf";//Response.Write("<script> alert('已生成pdf');</script>");}#endregion#region 添加表格protected void PdfTable_Click(object sender, EventArgs e){string pdfTemplate = Server.MapPath("~/PDFTemplate/pdfTemplate.pdf");string newpdf = Server.MapPath("~/PDFTemplate/newpdf4.pdf");//追加表格############StringBuilder tableHtml = new StringBuilder();tableHtml.Append(@"<table><tr><td>项目</td><td>细类</td><td>价格</td><td>数量</td><td>投放时间</td><td>金额</td></tr><tr><td>钻石会员</td><td>基础服务</td><td>69800元/月</td><td>1年</td><td>2016.01.03-2017.01.02</td><td>69800</td></tr><tr><td>核酸纯化系统专场</td><td>金榜题名</td><td>70000元/月</td><td>1年</td><td>2016.01.03-2017.01.02</td><td>7000</td></tr></table>");new PdfTable().PutTable(pdfTemplate, newpdf, tableHtml.ToString());iframepdf.Attributes["src"] = "../PDFTemplate/newpdf4.pdf";//Response.Write("<script> alert('已生成pdf');</script>");}#endregion}
}PdfPage.aspx.cs

 

查看全文
如若内容造成侵权/违法违规/事实不符,请联系编程学习网邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

相关文章

  1. QML 编程之旅 -- QML程序的基本结构概念

    文章目录QML 文档的构成QML基本语法 QML 编程之旅 – QML程序的基本结构概念 学习Qt编程快近一年了,的确是项目驱动,让我不得不咬紧牙关,需要快速的学习掌握一门新的技术。编程是一个非常累的学习过程,不但基本的逻辑思维能力要强,同时也非常考验阅读能力。到了一定年纪,…...

    2024/5/7 12:56:09
  2. 部署一个docker镜像

    #创建宿主机目录,运行文件txt_to_csv.py和数据文件combineTextbk2020-08-24.0.zip拷贝到/app中,/data中保存结果文件 mkdir -m 777 /projects #添加执行权限 chmod a+x txt_to_csv.py #解压容器镜像 gzip -d python-3.6.2-centos-setup.tar.gz #加载容器镜像 docker load -i …...

    2024/5/7 16:10:20
  3. 设计模式系列(创建型模式)之二 抽象工厂模式

    抽象工厂模式 抽象工厂模式(Abstract factory pattern)是一种为访问类提供一个创建一组相关或相互依赖对象的接口,且访问类无须指定所要产品的具体类就能得到同族的不同等级的产品的模式结构。 抽象工厂模式是工厂方法模式的升级版本,工厂方法模式只生产一个等级的产品,而…...

    2024/4/28 0:46:54
  4. SpringCloud使用 Nacos做注册中心 客户端启动报错java.lang.IllegalArgumentException: no server available的解决方案

    困扰我很多天的问题了,报错 no server available Error watching Nacos Service change java.lang.IllegalArgumentException: no server availableat com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:354) ~[nacos-client-1.0.0.jar:na]at com.ali…...

    2024/5/1 15:32:02
  5. vscode终端运行python出现的警告

    警告信息 libpng warning: iCCP: cHRM chunk does not match sRGB 解决方法 关闭QQ输入法...

    2024/4/28 21:54:50
  6. Mac 电脑忘记电脑root密码

    一、打开终端 # sudo passwd root # 输入密码 # 再次输出密码 # su # 输入密码参考地址...

    2024/5/7 21:46:56
  7. 机器翻译与自动文摘评价指标 BLEU 和 ROUGE

    https://baijiahao.baidu.com/s?id=1655137746278637231&wfr=spider&for=pc...

    2024/4/28 4:46:07
  8. 刷脸支付成了当下最有价值的风口

    政策利好,大佬站台,媒体刷屏,刷脸支付毫无疑问已成了当下最有价值的风口之一,而对于大部分草根创业者而言,成为代理商是参与到这一万亿蓝海市场的唯一选择。 刷脸支付代理商的的盈利来源很多,但基本是由微信与支付宝官方所决定的,可以归纳为设备销售、流水分润、刷脸返现…...

    2024/4/28 14:10:55
  9. QTableView QStandardItemModel QStandardItem三者的关系 个人笔记

    三者关系 如果把QTableView看作画框的话,那么,QStandardItemModel就是画框里的画,QStandardItem是画里的人物。 QStandardItem QStandardItem是存储数据的单元格,它存储的是QString 常用样式: QStandardItem* item = new QStandardItem(QString::fromLocal8Bit("hell…...

    2024/4/27 11:54:45
  10. win10环境下配置golang+vscode【解决install failed情况】

    博客目录(阅读时间:3分钟)1. 配置golang环境①下载相关软件②创建gowork工作空间③配置环境变量④验证环境配置结果2. 配置vscode go环境①安装vscode的go插件②尝试运行③vscode运行报错情况④vscode go配置3. 其他可能遇到的问题 1. 配置golang环境 ①下载相关软件 go1.15…...

    2024/5/7 13:33:33
  11. cmake-变量作用域

    本文的目标是讲讲cmake中的变量。在一个复杂的cmake工程中,变量经常会被传来传去,只有搞懂变量的原理和本质,才能以不变应万变,而不会出现"变量的值是从哪儿来的问题"。要想将变量讲清楚,涉及的新的知识点还比较多,看完本文一定有所收获。 文章目录变量(variab…...

    2024/5/4 19:45:47
  12. java之IO操作

    IO操作 IO操作,表示的是输入输出操作,那么在IO操作中,操作的对象是流,比如要从将A的数据写入到B中,那么就必须使用字节流或者字符流完成。 一、文件操作类 在Java中,File类是唯一可以代表磁盘的类,可以对磁盘上的文件及文件夹进行创建,删除,修改文件的最后修改时间,取…...

    2024/5/2 20:48:11
  13. ElementUI中el-form实现表单重置以及将方法抽出为全局方法

    场景使用el-form时,点击重置按钮或者取消按钮时会实现表单重置效果。那么el-form怎样实现表单重置,如果在多个页面需要用到重置,怎样将此方法抽出为全局的方法,在需要用到的地方直接引用。注:博客:https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获…...

    2024/4/28 5:20:42
  14. cf#1397 A. Juggling Letters

    惯例,先粘个生草翻译 题意大概就是给你nnn个字符串,你可以讲其中的字母任意移动,问是否有可能让这nnn个字符串变成同样的字符串 我们可以另辟蹊径,直接看如果可以的话需要满足什么条件 因为每个字符串最后都相等了,所以只要出现过的字母的出现次数一定是nnn的倍数(可能一…...

    2024/5/8 1:02:48
  15. 电脑屏幕闪屏解决办法

    显示屏物理调最亮,避免闪屏。 xrandr --output HDMI-1 --brightness 0.7设置屏幕亮度xgamma -gamma 0.75 伽马值设置...

    2024/4/28 7:12:56
  16. StreamSets FAQ(一)使用binglog同步MySQL数据到kudu,date数据类型在两端不一致

    1、问题描述使用streamsets将mysql数据同步到kudu中,直接解析mysql的binlog进行实时数据同步,发现一个小的细节问题,mysql中定义的date类型的字段在解析binlog后变成了带有星期几标致的值,如create字段是date类型,值为2019-06-19,那么streamsets的mysqlbinlog就会将其解析…...

    2024/4/29 5:10:25
  17. WordPress功能最齐全的数据库重置插件WP Reset

    我们在测试 WordPress 各种主题或插件的时候,会在数据库中增加很多选项,有时候将插件和主题删除了这些内容都还会存在数据库中,平时我们都是手工清理数据库,非常繁杂。以前跟大家介绍过一款WordPress 站点重置插件 WordPress Reset,只能一键恢复至安装初始状态,不够灵活,…...

    2024/4/28 5:44:34
  18. Linux出现Read-only file system错误的解决方法

    Linux出现Read-only file system错误的解决方法参考文章: (1)Linux出现Read-only file system错误的解决方法 (2)https://www.cnblogs.com/jxldjsn/p/11337990.html 备忘一下。...

    2024/4/28 3:08:13
  19. 简历图标资源分享

    关注公众号《小杨的python之路》回复“简历图标”关注公众号《小杨的python之路》回复“简历图标”...

    2024/4/29 6:13:23
  20. i5-10200h怎么样

    i5-10200H的酷睿处理器,它采用4核心8线程,和我们熟悉的i5-10300H相比,默认主频从2.5GHz降为了2.4GHz,最高(单核)睿频加速频率从4.5GHz降为了4.1GHz,综合性能下降了大约10%不到,但却换来了更低的采购价格。 i5-10200h怎么样 这些点很重要!看完你就知道了 https://list.…...

    2024/4/29 1:15:06

最新文章

  1. Vue本地存储(cookie、sessionStorage,localStorage)

    Vue本地存储&#xff08;cookie、sessionStorage&#xff0c;localStorage&#xff09; 简介 cookie&#xff1a;登录信息存储在cookie中&#xff0c;有过期时间&#xff0c;过期后即失效sessionStorage&#xff1a;存储在浏览器&#xff0c;浏览器关闭后失效localStorage&am…...

    2024/5/8 3:00:18
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/5/7 10:36:02
  3. [Spring Cloud] gateway全局异常捕捉统一返回值

    文章目录 处理转发失败的情况全局参数同一返回格式操作消息对象AjaxResult返回值状态描述对象AjaxStatus返回值枚举接口层StatusCode 全局异常处理器自定义通用异常定一个自定义异常覆盖默认的异常处理自定义异常处理工具 在上一篇章时我们有了一个简单的gateway网关 [Spring C…...

    2024/5/8 1:47:24
  4. Go语言中如何实现继承

    完整课程请点击以下链接 Go 语言项目开发实战_Go_实战_项目开发_孔令飞_Commit 规范_最佳实践_企业应用代码-极客时间 Go语言中没有传统意义上的类和继承的概念&#xff0c;但可以通过嵌入类型&#xff08;embedded types&#xff09;来实现类似的功能。嵌入类型允许一个结构…...

    2024/5/5 8:37:47
  5. 416. 分割等和子集问题(动态规划)

    题目 题解 class Solution:def canPartition(self, nums: List[int]) -> bool:# badcaseif not nums:return True# 不能被2整除if sum(nums) % 2 ! 0:return False# 状态定义&#xff1a;dp[i][j]表示当背包容量为j&#xff0c;用前i个物品是否正好可以将背包填满&#xff…...

    2024/5/7 19:05:20
  6. 【Java】ExcelWriter自适应宽度工具类(支持中文)

    工具类 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet;/*** Excel工具类** author xiaoming* date 2023/11/17 10:40*/ public class ExcelUti…...

    2024/5/7 22:31:36
  7. Spring cloud负载均衡@LoadBalanced LoadBalancerClient

    LoadBalance vs Ribbon 由于Spring cloud2020之后移除了Ribbon&#xff0c;直接使用Spring Cloud LoadBalancer作为客户端负载均衡组件&#xff0c;我们讨论Spring负载均衡以Spring Cloud2020之后版本为主&#xff0c;学习Spring Cloud LoadBalance&#xff0c;暂不讨论Ribbon…...

    2024/5/8 1:37:40
  8. TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案

    一、背景需求分析 在工业产业园、化工园或生产制造园区中&#xff0c;周界防范意义重大&#xff0c;对园区的安全起到重要的作用。常规的安防方式是采用人员巡查&#xff0c;人力投入成本大而且效率低。周界一旦被破坏或入侵&#xff0c;会影响园区人员和资产安全&#xff0c;…...

    2024/5/7 14:19:30
  9. VB.net WebBrowser网页元素抓取分析方法

    在用WebBrowser编程实现网页操作自动化时&#xff0c;常要分析网页Html&#xff0c;例如网页在加载数据时&#xff0c;常会显示“系统处理中&#xff0c;请稍候..”&#xff0c;我们需要在数据加载完成后才能继续下一步操作&#xff0c;如何抓取这个信息的网页html元素变化&…...

    2024/5/8 1:37:39
  10. 【Objective-C】Objective-C汇总

    方法定义 参考&#xff1a;https://www.yiibai.com/objective_c/objective_c_functions.html Objective-C编程语言中方法定义的一般形式如下 - (return_type) method_name:( argumentType1 )argumentName1 joiningArgument2:( argumentType2 )argumentName2 ... joiningArgu…...

    2024/5/7 16:57:02
  11. 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】

    &#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【洛谷算法题】 文章目录 【洛谷算法题】P5713-洛谷团队系统【入门2分支结构】&#x1f30f;题目描述&#x1f30f;输入格…...

    2024/5/7 14:58:59
  12. 【ES6.0】- 扩展运算符(...)

    【ES6.0】- 扩展运算符... 文章目录 【ES6.0】- 扩展运算符...一、概述二、拷贝数组对象三、合并操作四、参数传递五、数组去重六、字符串转字符数组七、NodeList转数组八、解构变量九、打印日志十、总结 一、概述 **扩展运算符(...)**允许一个表达式在期望多个参数&#xff0…...

    2024/5/7 1:54:46
  13. 摩根看好的前智能硬件头部品牌双11交易数据极度异常!——是模式创新还是饮鸩止渴?

    文 | 螳螂观察 作者 | 李燃 双11狂欢已落下帷幕&#xff0c;各大品牌纷纷晒出优异的成绩单&#xff0c;摩根士丹利投资的智能硬件头部品牌凯迪仕也不例外。然而有爆料称&#xff0c;在自媒体平台发布霸榜各大榜单喜讯的凯迪仕智能锁&#xff0c;多个平台数据都表现出极度异常…...

    2024/5/7 21:15:55
  14. Go语言常用命令详解(二)

    文章目录 前言常用命令go bug示例参数说明 go doc示例参数说明 go env示例 go fix示例 go fmt示例 go generate示例 总结写在最后 前言 接着上一篇继续介绍Go语言的常用命令 常用命令 以下是一些常用的Go命令&#xff0c;这些命令可以帮助您在Go开发中进行编译、测试、运行和…...

    2024/5/8 1:37:35
  15. 用欧拉路径判断图同构推出reverse合法性:1116T4

    http://cplusoj.com/d/senior/p/SS231116D 假设我们要把 a a a 变成 b b b&#xff0c;我们在 a i a_i ai​ 和 a i 1 a_{i1} ai1​ 之间连边&#xff0c; b b b 同理&#xff0c;则 a a a 能变成 b b b 的充要条件是两图 A , B A,B A,B 同构。 必要性显然&#xff0…...

    2024/5/7 16:05:05
  16. 【NGINX--1】基础知识

    1、在 Debian/Ubuntu 上安装 NGINX 在 Debian 或 Ubuntu 机器上安装 NGINX 开源版。 更新已配置源的软件包信息&#xff0c;并安装一些有助于配置官方 NGINX 软件包仓库的软件包&#xff1a; apt-get update apt install -y curl gnupg2 ca-certificates lsb-release debian-…...

    2024/5/7 16:04:58
  17. Hive默认分割符、存储格式与数据压缩

    目录 1、Hive默认分割符2、Hive存储格式3、Hive数据压缩 1、Hive默认分割符 Hive创建表时指定的行受限&#xff08;ROW FORMAT&#xff09;配置标准HQL为&#xff1a; ... ROW FORMAT DELIMITED FIELDS TERMINATED BY \u0001 COLLECTION ITEMS TERMINATED BY , MAP KEYS TERMI…...

    2024/5/8 1:37:32
  18. 【论文阅读】MAG:一种用于航天器遥测数据中有效异常检测的新方法

    文章目录 摘要1 引言2 问题描述3 拟议框架4 所提出方法的细节A.数据预处理B.变量相关分析C.MAG模型D.异常分数 5 实验A.数据集和性能指标B.实验设置与平台C.结果和比较 6 结论 摘要 异常检测是保证航天器稳定性的关键。在航天器运行过程中&#xff0c;传感器和控制器产生大量周…...

    2024/5/7 16:05:05
  19. --max-old-space-size=8192报错

    vue项目运行时&#xff0c;如果经常运行慢&#xff0c;崩溃停止服务&#xff0c;报如下错误 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 因为在 Node 中&#xff0c;通过JavaScript使用内存时只能使用部分内存&#xff08;64位系统&…...

    2024/5/8 1:37:31
  20. 基于深度学习的恶意软件检测

    恶意软件是指恶意软件犯罪者用来感染个人计算机或整个组织的网络的软件。 它利用目标系统漏洞&#xff0c;例如可以被劫持的合法软件&#xff08;例如浏览器或 Web 应用程序插件&#xff09;中的错误。 恶意软件渗透可能会造成灾难性的后果&#xff0c;包括数据被盗、勒索或网…...

    2024/5/8 1:37:31
  21. JS原型对象prototype

    让我简单的为大家介绍一下原型对象prototype吧&#xff01; 使用原型实现方法共享 1.构造函数通过原型分配的函数是所有对象所 共享的。 2.JavaScript 规定&#xff0c;每一个构造函数都有一个 prototype 属性&#xff0c;指向另一个对象&#xff0c;所以我们也称为原型对象…...

    2024/5/7 11:08:22
  22. C++中只能有一个实例的单例类

    C中只能有一个实例的单例类 前面讨论的 President 类很不错&#xff0c;但存在一个缺陷&#xff1a;无法禁止通过实例化多个对象来创建多名总统&#xff1a; President One, Two, Three; 由于复制构造函数是私有的&#xff0c;其中每个对象都是不可复制的&#xff0c;但您的目…...

    2024/5/7 7:26:29
  23. python django 小程序图书借阅源码

    开发工具&#xff1a; PyCharm&#xff0c;mysql5.7&#xff0c;微信开发者工具 技术说明&#xff1a; python django html 小程序 功能介绍&#xff1a; 用户端&#xff1a; 登录注册&#xff08;含授权登录&#xff09; 首页显示搜索图书&#xff0c;轮播图&#xff0…...

    2024/5/8 1:37:29
  24. 电子学会C/C++编程等级考试2022年03月(一级)真题解析

    C/C++等级考试(1~8级)全部真题・点这里 第1题:双精度浮点数的输入输出 输入一个双精度浮点数,保留8位小数,输出这个浮点数。 时间限制:1000 内存限制:65536输入 只有一行,一个双精度浮点数。输出 一行,保留8位小数的浮点数。样例输入 3.1415926535798932样例输出 3.1…...

    2024/5/7 17:09:45
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57