GVKun编程网logo

编辑iTextSharp PdfSmartCopy类的DirectContent(istylepdf编辑文本)

16

在本文中,我们将详细介绍编辑iTextSharpPdfSmartCopy类的DirectContent的各个方面,并为您提供关于istylepdf编辑文本的相关解答,同时,我们也将为您带来关于AWSC

在本文中,我们将详细介绍编辑iTextSharp PdfSmartCopy类的DirectContent的各个方面,并为您提供关于istylepdf编辑文本的相关解答,同时,我们也将为您带来关于AWS Chime SDK |仅对“本地”用户触发contentShareObserver.contentShareDidStop()、c# – 使用iTextSharp锁定PDF以防编辑、C#使用iTextSharp+ZXing.Net+FreeSpire.PDF生成和打印pdf文档、cocos2d-x getBoundingBox getContentSize getTextureRect 解释的有用知识。

本文目录一览:

编辑iTextSharp PdfSmartCopy类的DirectContent(istylepdf编辑文本)

编辑iTextSharp PdfSmartCopy类的DirectContent(istylepdf编辑文本)

在我的工作中,有时我必须合并几个到几百个pdf文件。我一直在使用WriterImportedPages类。但是,当我将所有文件合并为一个文件时,文件大小将变得很大,这是所有合并文件大小的总和,这是因为字体附在每个页面上,而不被重用(字体嵌入到每个页面中,而不是整个文档中)。

不久前,我发现了有关PdfSmartCopy类的知识,该类可以重用嵌入式字体和图像。问题就来了。很多时候,在将文件合并在一起之前,我必须向它们添加其他内容(图像,文本)。为此,我通常使用PdfContentBytefrom
Writer对象。

Document doc = new Document();    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\test.pdf", FileMode.Create));PdfContentByte cb = writer.DirectContent;cb.Rectangle(100, 100, 100, 100);cb.SetColorStroke(BaseColor.RED);cb.SetColorFill(BaseColor.RED);cb.FillStroke();

当我对PdfSmartCopy对象执行类似操作时,页面会合并,但不会添加任何其他内容。我的测试的完整代码PdfSmartCopy

using (Document doc = new Document())        {            using (PdfSmartCopy copy = new PdfSmartCopy(doc, new FileStream(Path.GetDirectoryName(pdfPath[0]) + "\\testas.pdf", FileMode.Create)))            {                doc.Open();                PdfContentByte cb = copy.DirectContent;                for (int i = 0; i < pdfPath.Length; i++)                {                    PdfReader reader = new PdfReader(pdfPath[i]);                    for (int ii = 0; ii < reader.NumberOfPages; ii++)                    {                        PdfImportedPage import = copy.GetImportedPage(reader, ii + 1);                                                    copy.AddPage(import);                        cb.Rectangle(100, 100, 100, 100);                        cb.SetColorStroke(BaseColor.RED);                        cb.SetColorFill(BaseColor.RED);                        cb.FillStroke();                        doc.NewPage();// net nesessary line                        //ColumnText col = new ColumnText(cb);                        //col.SetSimpleColumn(100,100,500,500);                        //col.AddText(new Chunk("wdasdasd", PdfFontManager.GetFont(@"C:\Windows\Fonts\arial.ttf", 20)));                        //col.Go();                                                }                }            }        }    }

现在我有几个问题:

  1. 是否可以编辑PdfSmartCopy对象的DirectContent?
  2. 如果不是,是否有另一种方法可以将多个pdf文件合并为一个文件,而不会显着增加其大小,并且仍然能够在合并时向页面添加其他内容?

答案1

小编典典

首先,使用PdfWriter/
PdfImportedPage不是一个好主意。您将放弃所有交互式功能!作为iText的作者,尽管我写了两本书有关这一事实,并且尽管我说服了出版商为iText提供最重要的章节之一,但令如此之多的人犯同样的错误却非常沮丧。免费:http
:
//www.manning.com/lowagie2/samplechapter6.pdf

我的写作真的那么糟糕吗?还是有人继续使用PdfWriter/ 合并文档的另一个原因PdfImportedPage

至于您的具体问题,以下是答案:

  1. 是。下载示例章节并在PDF文件中搜索PageStamp
  2. 仅当您通过两次创建PDF时。例如:首先创建巨大的PDF,然后通过传递来减小大小PdfCopy;或先使用PdfCopy创建合并的PDF,然后使用进行第二遍添加额外的内容PdfStamper

AWS Chime SDK |仅对“本地”用户触发contentShareObserver.contentShareDidStop()

AWS Chime SDK |仅对“本地”用户触发contentShareObserver.contentShareDidStop()

如何解决AWS Chime SDK |仅对“本地”用户触发contentShareObserver.contentShareDidStop()?

我正在使用await meetingSession.audioVideo.stopContentShare();结束屏幕共享。但是,仅针对“本地”参与者触发contentShareObserver.contentShareDidStop()中的回调,而不会在其他任何客户端上触发。

什么是正确的回调,以便每个与会者都可以收到屏幕共享已停止的消息/呼叫?

我想做的是...单击“停止屏幕共享”按钮后,只需在所有与会者的设备上隐藏屏幕共享视频容器即可。

除了contentShareDidStop之外,我还尝试使用audioVideoDidUpdate,但是在调用stopContentShare()时永远不会调用它。

谢谢。

编辑: 我还尝试了许多可用的接口 ScreenSharingSessionObserver似乎很明显,但是我不知道如何将其连接起来。没有任何内容……没有解释这些接口的工作方式。您可以从AWS获得基本的101简介,然后就可以猜测所有内容。绝对令人生气!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

c# – 使用iTextSharp锁定PDF以防编辑

c# – 使用iTextSharp锁定PDF以防编辑

我使用iTextSharp创建了一个C#程序,用于阅读PDF,附加社会DRM内容,然后保存文件.如何锁定这个新的PDF,进一步编辑?

我希望用户能够在不输入密码的情况下查看该文件,而我不介意选择/复制操作,但我记住删除社交DRM的能力.

解决方法

加密您的PDF文档.简单的HTTP处理程序工作示例让您开始:
<%@ WebHandler Language="C#"%>
using System;
using System.Web;
using iTextSharp.text;
using iTextSharp.text.pdf;

public class lockPdf : IHttpHandler {
  public void ProcessRequest (HttpContext context) {
    HttpServerUtility Server = context.Server;
    HttpResponse Response = context.Response;
    Response.ContentType = "application/pdf";
    using (Document document = new Document()) {
      PdfWriter writer = PdfWriter.GetInstance(
        document,Response.OutputStream
      );
      writer.SetEncryption(
// null user password => users can open document __without__ pasword
        null,// owner password => required to __modify__ document/permissions        
        System.Text.Encoding.UTF8.GetBytes("ownerPassword"),/*
 * bitwise or => see iText API for permission parameter:
 * http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfWriter.html
 */
        PdfWriter.ALLOW_PRINTING
            | PdfWriter.ALLOW_copY,// encryption level also in documentation referenced above        
        PdfWriter.ENCRYPTION_AES_128
      );
      document.open();
      document.Add(new Paragraph("hello world"));
    }
  }
  public bool IsReusable { get { return false; } }
}

内联评论应该是不言自明的.见PdfWriter documentation.

您还可以使用使用PdfEncryptor class的PdfReader对象加密PDF文档.换句话说,您还可以执行此操作(未测试):

PdfReader reader = new PdfReader(INPUT_FILE);
using (MemoryStream ms = new MemoryStream()) {
  using (pdfstamper stamper = new pdfstamper(reader,ms)) {
    // add your content
  }
  using (FileStream fs = new FileStream(
    OUTPUT_FILE,FileMode.Create,FileAccess.ReadWrite))
  {
    PdfEncryptor.Encrypt(
      new PdfReader(ms.ToArray()),fs,null,System.Text.Encoding.UTF8.GetBytes("ownerPassword"),PdfWriter.ALLOW_PRINTING
          | PdfWriter.ALLOW_copY,true
    );
  }  
}

C#使用iTextSharp+ZXing.Net+FreeSpire.PDF生成和打印pdf文档

C#使用iTextSharp+ZXing.Net+FreeSpire.PDF生成和打印pdf文档

项目需求(Winform)可以批量打印某个模板,经过百度和摸索,使用iTextSharp+ZXing.Net+FreeSpire.PDF三个类库实现了生成pdf、生成条形码和打印pdf功能。

首先在项目作用使用NuGet获取这三个类库的引用。

其次把C:\Windows\Fonts里面的微软雅黑字体复制到bin\debug\Fonts目录下

以下为实现代码:

using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using iTextSharp.text;
using iTextSharp.text.pdf;
using it = iTextSharp.text;
using System.Drawing.Imaging;
 
        //打印确认表
        private void Btn_print_Click(object sender, EventArgs e)
        {
            string path = Application.StartupPath + "\\PDFs";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            //使用微软雅黑字体,解决中文无法显示,注意msyh.ttc后面的,0是必须的
            BaseFont baseFont = BaseFont.CreateFont(Application.StartupPath + "\\Fonts\\msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            it.Font font = new it.Font(baseFont, 14, it.Font.BOLD, it.BaseColor.BLACK);
            using (var doc1 = new Document(PageSize.A4, 5, 5, 35, 5))
            {
                PdfWriter.GetInstance(doc1, new FileStream(path + "\\Doc1.pdf", FileMode.Create));
                doc1.Open();
                //生成条形码
                var bmp = ZXingHelper.GenerateBarcode("12345678900000");
                var txm = it.Image.GetInstance(System.Drawing.Image.FromHbitmap(bmp), ImageFormat.Bmp);
                //txm.ScalePercent(24f);
                txm.ScaleAbsoluteHeight(40);
                txm.SetAbsolutePosition(doc1.PageSize.Width - 220, doc1.PageSize.Height - 32);
                doc1.Add(txm);//把条形码放到页面右上角
 
                PdfPTable table = new PdfPTable(7);
 
                PdfPCell cell = new PdfPCell(new Phrase("X X X X 验 证 意 见 确 认 处 理 记 录 表", font))
                {
                    Colspan = 7,
                    Border = 0,
                    MinimumHeight = 30,
                    HorizontalAlignment = 1
                };
                table.AddCell(cell);
 
                it.Font fontCell = new it.Font(baseFont, 10, it.Font.NORMAL, it.BaseColor.BLACK);
                float[] cellWidths = new float[] { 10, 35, 35, 45, 40, 65, 40 };
                table.SetWidths(cellWidths);
 
                cell = new PdfPCell(new Phrase("县区:          XX:          XX:           XXXX:               日期:   月     日          时间:        ", fontCell))
                {
                    Colspan = 7,
                    Border = 0,
                    HorizontalAlignment = 0,
                    MinimumHeight = 15
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("座\r\n号", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5,
                    MinimumHeight = 35
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("姓 名", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("xx号", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("XX(通过/未通过/未验证)", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("XXXX(采集/未采集)", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("验证意见(XX/XX/XXXX/XXXX)", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                cell = new PdfPCell(new Phrase("XXXX确认处理情况)", fontCell))
                {
                    HorizontalAlignment = 1,
                    VerticalAlignment = 5
                };
                table.AddCell(cell);
 
                for (var i = 1; i < 31; i++)
                {
                    table.AddCell(new PdfPCell(new Phrase(i.ToString(), fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5,
                        MinimumHeight = 17
                    });
                    table.AddCell(new PdfPCell(new Phrase("正大·光明龑", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                    table.AddCell(new PdfPCell(new Phrase(" ", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                    table.AddCell(new PdfPCell(new Phrase(" ", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                    table.AddCell(new PdfPCell(new Phrase(" ", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                    table.AddCell(new PdfPCell(new Phrase(" ", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                    table.AddCell(new PdfPCell(new Phrase(" ", fontCell))
                    {
                        HorizontalAlignment = 1,
                        VerticalAlignment = 5
                    });
                }
 
                fontCell = new it.Font(baseFont, 12, it.Font.NORMAL, it.BaseColor.BLACK);
                cell = new PdfPCell(new Phrase("XXXXX签字:                                               XXXXX丙签字:                        ", fontCell))
                {
                    Colspan = 7,
                    Border = 0,
                    MinimumHeight = 20,
                    HorizontalAlignment = 0
                };
                table.AddCell(cell);
 
                it.Font fontFooter = new it.Font(baseFont, 10, it.Font.NORMAL, it.BaseColor.BLACK);
                PdfPCell cellFooter = new PdfPCell(new Phrase("说明:1.文字描述文字描述文字描述文字描述文字描述文字描述文字描述\r\n2、文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述;3、文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述,存档备查。", fontFooter))
                {
                    Colspan = 7,
                    Border = 0,
                    MinimumHeight = 40,
                    Left = 0,
                    PaddingLeft = 0,
                    HorizontalAlignment = 0//0=Left, 1=Centre, 2=Right
                };
                table.AddCell(cellFooter);
                doc1.Add(table);
                doc1.Close();
            }
            if (MessageBox.Show("生成成功,是否打印?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument(path + "\\Doc1.pdf"); 
                pdf.Print();
            }
 
        }

  条形码生成的代码

public static IntPtr GenerateBarcode(string barcode)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.CODE_128;
            writer.Options = new ZXing.Common.EncodingOptions
            {
                Height = 100,
                Width = 200,
                PureBarcode = false
            };
 
            Bitmap bitmap = writer.Write(barcode);
            return bitmap.GetHbitmap();
        }

  

cocos2d-x getBoundingBox getContentSize getTextureRect 解释

cocos2d-x getBoundingBox getContentSize getTextureRect 解释

这是cocos2d-x代码看注释的解释 翻译的 不到之处谅解 后面在总结
getBoundingBox // 返回一个AABB(axis-aligned bounding-Box)在其父母的坐标系统。Returns an AABB (axis-aligned bounding-Box) in its parent's coordinate system.
getContentSize //节点容量大小
getTextureRect //返回精灵矩形的点

例子1
{
图片 Icon-48.png 这种图片 48 × 48 pixels 标准icon中得一个
Sprite *pSpBox=Sprite::create("Icon-48.png");
pSpBox->setPosition(Vec2(m_pWinSize.width*0.5,m_pWinSize.height*0.5));
pSpBox->setScale(0.2f);
addChild(pSpBox);
{
cclOG(" A ");
Rect rect=pSpBox-> ();
Size size=pSpBox-> getContentSize sizea=pSpBox-> BoundingBox(%f,%f,%f) ",rect.origin.x,rect.origin.y,rect.size.width,rect.size.height);
ContentSize(%f,size.width,size.height);
TextureRect(%f,sizea.origin.x,sizea.origin.y,sizea.size.width,sizea.size.height);
}
pSpBox->setScale(0.5f);
cclOG("B");
cocos2d: A
cocos2d: BoundingBox(475.200012,315.200012,9.600006,9.600006)
cocos2d: ContentSize(48.000000,48.000000)
cocos2d: TextureRect(0.000000,0.000000,48.000000,51); font-family:Arial; font-size:14px; line-height:26px">cocos2d: B
cocos2d: BoundingBox(468.000000,308.000000,24.000000,24.000000)
}
例子2

图片 Icon-48.png 这种图片 48 × 48 pixels 标准icon中得一个

SpriteFrameCache::getInstance()->addSpriteFramesWithFile("haohaoxuexi.plist");//把现有的icon图片整到一个大图中测试
Sprite *pSpBox=Sprite::createWithSpriteFrameName("Icon-48.png");//create("Icon-48.png");

cclOG(" B //输出结果
cocos2d: TextureRect(447.000000,1616.000000,51); font-family:Arial; font-size:14px; line-height:26px"> //"haohaoxuexi.plist" 中图片Icon-48.png 数据做参考
<key>Icon-48.png</key>
<dict>
<key>frame</key>
<string>{{447,1616},{48,48}}</string>
<key>offset</key>
<string>{0,0}</string>
<key>rotated</key>
<false/>
<key>sourceColorRect</key>
<string>{{0,0},48}}</string>
<key>sourceSize</key>
<string>{48,48}</string>
</dict>
应该都知道什么意思了,还是总结一下吧

getBoundingBox 中得 Size.width .height 显示图片真实大小 (考虑缩放和不缩放)
getContentSize 纹理图片大小
getTextureRect 当前的纹理在总纹理的位置 (不考虑 缩放不缩放)


图片有缩放 就用 getBoundingBox ,不考虑缩放用 getContentSize
看需求用哪个?
getBoundingBox 中得 origin.x .y 本人也不知道什么意思,打印出来没有看懂。前做这点解释,知道后在更新
原文地址: http://www.jb51.cc/article/p-mqsqfpet-ye.html

我们今天的关于编辑iTextSharp PdfSmartCopy类的DirectContentistylepdf编辑文本的分享就到这里,谢谢您的阅读,如果想了解更多关于AWS Chime SDK |仅对“本地”用户触发contentShareObserver.contentShareDidStop()、c# – 使用iTextSharp锁定PDF以防编辑、C#使用iTextSharp+ZXing.Net+FreeSpire.PDF生成和打印pdf文档、cocos2d-x getBoundingBox getContentSize getTextureRect 解释的相关信息,可以在本站进行搜索。

本文标签: