Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将QRCODE添加到通过EventReceiver(iTextSharp、SharePoint和QRCoder)上载到文档库的文档中_C#_Sharepoint_Itext - Fatal编程技术网

C# 将QRCODE添加到通过EventReceiver(iTextSharp、SharePoint和QRCoder)上载到文档库的文档中

C# 将QRCODE添加到通过EventReceiver(iTextSharp、SharePoint和QRCoder)上载到文档库的文档中,c#,sharepoint,itext,C#,Sharepoint,Itext,当用户将PDF文档上传到文档库并使用元数据(称为“DocumentCode”的新字段)将其签入时,我尝试在PDF文档上标记QRCode 据我所知,我必须签出它,从签出的文档中读取DocumentCode值,使用NuGet的“QRCODER”生成QRCode,使用PDFStamper使用iTextSharp在第一页上盖章 我放弃了在不寻求帮助的情况下解决问题,所以我来这里寻求帮助 这是我写的代码: using Microsoft.SharePoint; using System.IO; using

当用户将PDF文档上传到文档库并使用元数据(称为“DocumentCode”的新字段)将其签入时,我尝试在PDF文档上标记QRCode

据我所知,我必须签出它,从签出的文档中读取DocumentCode值,使用NuGet的“QRCODER”生成QRCode,使用PDFStamper使用iTextSharp在第一页上盖章

我放弃了在不寻求帮助的情况下解决问题,所以我来这里寻求帮助

这是我写的代码:

using Microsoft.SharePoint;
using System.IO;
using System.Drawing;
using iTextSharp.text.pdf;
using QRCoder;

namespace WFA.CodeTestReceiver
{

    public class CodeTestReceiver : SPItemEventReceiver
    {

        public override void ItemUpdated(SPItemEventProperties properties)
        {
            using (SPWeb web = properties.OpenWeb())
            {
                SPFile UploadedFile = properties.ListItem.File;
                byte[] FileContent = UploadedFile.OpenBinary();
                QRCodeGenerator qrCodeGen = new QRCodeGenerator();
                QRCodeData qrCodeData = qrCodeGen.CreateQrCode(properties.ListItem["DocumentCode"].ToString(), QRCodeGenerator.ECCLevel.Q, true, false);
                BitmapByteQRCode qrBitmap = new BitmapByteQRCode(qrCodeData);
                byte[] qrBytes = qrBitmap.GetGraphic(6);
                byte[] NewFile;

                MemoryStream MS = new MemoryStream(qrBytes);

                using (Stream iPDF = new MemoryStream(FileContent))
                using (Stream iIMG = new MemoryStream(qrBytes))
                using (Stream oPDF = new MemoryStream())
                {
                    var reader = new PdfReader(iPDF);
                    var stamper = new PdfStamper(reader, oPDF);
                    var PDC = stamper.GetOverContent(1);
                    var pSize = reader.GetPageSize(1);

                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(iIMG);
                    Point P = new Point(0, 0);
                    P.X = 50;
                    P.Y = 700;
                    int Y = (int)(pSize.Height - P.Y);
                    image.SetAbsolutePosition(100, 300);
                    PDC.AddImage(image);
                    oPDF.CopyTo(MS);
                    NewFile = MS.ToArray();
                    stamper.Close();
                }
                SPFile sFile = web.Folders["CodeTest"].Files.Add(properties.ListItem.File.Name, NewFile, true);

            }
            base.ItemUpdated(properties);
        }


        public override void ItemCheckedIn(SPItemEventProperties properties)
        {
            using (SPWeb web = properties.OpenWeb())
            {

                SPFile UploadedFile = properties.ListItem.File;
                byte[] FileContent = UploadedFile.OpenBinary();
                QRCodeGenerator qrCodeGen = new QRCodeGenerator();
                QRCodeData qrCodeData = qrCodeGen.CreateQrCode(properties.ListItem["DocumentCode"].ToString(), QRCodeGenerator.ECCLevel.Q, true, false);
                BitmapByteQRCode qrBitmap = new BitmapByteQRCode(qrCodeData);
                byte[] qrBytes = qrBitmap.GetGraphic(6);
                byte[] NewFile;

                MemoryStream MS = new MemoryStream(qrBytes);

                using (Stream iPDF = new MemoryStream(FileContent))
                using (Stream iIMG = new MemoryStream(qrBytes))
                using (Stream oPDF = new MemoryStream())
                {
                    var reader = new PdfReader(iPDF);
                    var stamper = new PdfStamper(reader, oPDF);
                    var PDC = stamper.GetOverContent(1);
                    var pSize = reader.GetPageSize(1);

                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(iIMG);
                    Point P = new Point(0, 0);
                    P.X = 50;
                    P.Y = 700;
                    int Y = (int)(pSize.Height - P.Y);
                    image.SetAbsolutePosition(100, 300);
                    PDC.AddImage(image);
                    oPDF.CopyTo(MS);
                    NewFile = MS.ToArray();
                    stamper.Close();
                }
                SPFile sFile = web.Folders["CodeTest"].Files.Add(properties.ListItem.File.Name, NewFile, true);

            }
            base.ItemCheckedIn(properties);
        }
    }
}

你知道iText也可以生成条形码,包括二维码,作为原生的iText对象吗?不,这对我来说是新的。有任何参考或链接吗?看看你在哪一点上有问题/你到底在哪里需要帮助?对于QRCoder部分,我可能会帮助您,因为我已经编写了该库。。。