代码很简单设置PdfDocument.SecuritySettings.OwnerPassword
PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); doc.SecuritySettings.OwnerPassword = "123"; var filePath = $"b.pdf"; doc.Save(filePath);
XStringFormats 指定文本的位置:详请查看https://github.com/ststeiger/PdfSharpCore/blob/master/PdfSharpCore/Drawing/XStringFormats.cs
XFont font = new XFont("SimHei", 8); XBrush brush = XBrushes.Black; PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); for (int i = 0; i < doc.Pages.Count; i++) { PdfPage page = doc.Pages[i]; XRect layoutRectangle = new XRect(0, page.Height - font.Height, page.Width, font.Height); using (XGraphics gfx = XGraphics.FromPdfPage(page)) { gfx.DrawString( $"第{(i + 1).ToString()}页/共{doc.Pages.Count}页", font, brush, layoutRectangle, XStringFormats.BottomLeft); } }
XFont font = new XFont("SimHei", 8); XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0)); XPoint point = new XPoint(90, 20); PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); for (int i = 0; i < doc.Pages.Count; i++) { var renderer = XGraphics.FromPdfPage(doc.Pages[i]); XSize pageSize = renderer.PageSize; renderer.DrawString("xxx有限公司", font, brush, point); XPen pen = new XPen(XBrushes.Gray, 0.5f); renderer.DrawLine(pen, point.X, point.Y, pageSize.Width - point.X, point.Y); } doc.Save("b.pdf");
XFont font = new XFont("SimHei", 8); XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0)); PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); for (int i = 0; i < doc.Pages.Count; i++) { var renderer = XGraphics.FromPdfPage(doc.Pages[i]); XSize pageSize = renderer.PageSize; XPoint point = new XPoint(90, pageSize.Height-20); renderer.DrawString("xxx有限公司", font, brush, point); XPen pen = new XPen(XBrushes.Gray, 0.5f); renderer.DrawLine(pen, point.X, point.Y-10, pageSize.Width - point.X, point.Y-10); } doc.Save("b.pdf");
XFont font = new XFont("SimHei", 8); XBrush brush =new XSolidBrush(XColor.FromArgb(128, 255, 0, 0)); PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); for (int i = 0; i < doc.Pages.Count; i++) { XStringFormat stringFormat = new XStringFormat(); stringFormat.Alignment = XStringAlignment.Center; stringFormat.LineAlignment = XLineAlignment.Center; PdfPage page = doc.Pages[i]; var gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards); gfx.DrawString( $"xxx公司版权所有", font, brush, new XPoint(500, 500), stringFormat); } doc.Save("b.pdf");
//第一步先加载PDF文件 PdfDocument doc = PdfReader.Open(@"a.pdf", PdfDocumentOpenMode.Modify); //导入图片(地址,文件流) var background = XImage.FromFile(@"QRCode.png"); // var background = XImage.FromStream(()=> stream); //指定PDF 的页 PdfPage page = doc.Pages[0]; var gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards); //写入指定位置 gfx.DrawImage(background, 20, 20, 250, 140); doc.Save("b.pdf");
标签:icode9,语言, c++,编写,函数,高级功能,编译器,错误代码,网站,相片 来源:
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。