单个qr代码,用于5页的文档 [英] single qr code for a document of 5 pages

查看:67
本文介绍了单个qr代码,用于5页的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编码QR码的新手,并且有一个简单的问题。我注意到,当我将qr代码附加到文档时,无论文档页面大小是一个还是5个 - 它都将不同的qr代码编号附加到单个文档中的每个页面。是对的吗?我使用它来生成qr代码到分配,一些分配有多个页面。我应该有一个文档的单个qr代码,该代码在该文档的所有页面上都是相同的。



这是我的代码:



I am new to coding a QR codes and had a quick question. I noticed that when i am attaching a qr code to a document regardless of the document page size whether one or 5 - it is attaching a different qr code number to each page in a single document. Is that right? I am using this to generate qr code to assignments and some assignments have multiple pages. I should have a single qr code for the document which will be the same on all pages of that document.

here is my code:

for (int idx = 0; idx < inputDocument.PageCount; idx++)
                {

                    using (var dc = new DataContext())
                    {
                        // Add record stub for Assessment unless one already exists
                        Assessment a;
                        a = dc.Assessments.FirstOrDefault(
                            c => c.DocumentID == d.ID && c.FeedbackUserID == u.ID && c.PageNumber == idx + 1);
                        if (a == null)
                        {
                            a = new Assessment()
                            {
                                DocumentID = d.ID,
                                FeedbackUserID = u.ID,
                                PageNumber = idx + 1,
                                ID = Guid.NewGuid()
                            };
                        }
                        a.LastGeneratedDT = DateTime.UtcNow;
                        dc.SubmitChanges();

                        // Add copy of page to new document
                        PdfSharp.Pdf.PdfPage newpg = outputDocument.AddPage(inputDocument.Pages[idx]);

                        // Add tagging to the top or bottom of the page
                        PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(newpg);


                        string gurl = a.ID.ToString().Replace("-", "");
                        string gocr = "*" + gurl.Substring(0, 10) + " " + gurl.Substring(10, 11) + " " +
                                      gurl.Substring(21) + "*";
                        // prep the visible string

                        AddQRTag(gfx, 3, 3, baseQR + gurl, gocr);
                    }

                }

推荐答案



你可以在您的代码中看到您正在for循环中为每页添加QR代码。不应该是这样的:

Hi,
you can see in your code your are adding a QR code to per page inside the for loop. shouldn''t this be something like this:
foreach (Document inputDocument in Documents)
{
    string gurl = "";
    string gocr = "";
    PdfSharp.Drawing.XGraphics gfx;
    for (int idx = 0; idx < inputDocument.PageCount; idx++)
    {
        using (var dc = new DataContext())
        {
            // Add record stub for Assessment unless one already exists
            Assessment a;
            a = dc.Assessments.FirstOrDefault(
            c => c.DocumentID == d.ID && c.FeedbackUserID == u.ID && c.PageNumber == idx + 1);
            if (a == null)
            {
                a = new Assessment()
                {
                    DocumentID = d.ID,
                    FeedbackUserID = u.ID,
                    PageNumber = idx + 1,
                    ID = Guid.NewGuid()
                 };
            }
            a.LastGeneratedDT = DateTime.UtcNow;
            dc.SubmitChanges();

            // Add copy of page to new document
            PdfSharp.Pdf.PdfPage newpg = outputDocument.AddPage(inputDocument.Pages[idx]);
 
            // Add tagging to the top or bottom of the page
            gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(newpg);
 

            string gurl = a.ID.ToString().Replace("-", "");
            string gocr = "*" + gurl.Substring(0, 10) + " " + gurl.Substring(10, 11) + " " +
                                      gurl.Substring(21) + "*";
        }
    }
    // prep the visible string
    AddQRTag(gfx, 3, 3, baseQR + gurl, gocr);
}







问候

Jegan




Regards
Jegan


这篇关于单个qr代码,用于5页的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆