Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Apr 11, 2017 2:44 pm

Hello!

I`m using free version of Spire.PDF, so here is a 10 page license limit. I tried to create several files, to avoid limit, but I got a bug: my first file is normal, but second and all the others have some strange imposing of "artifacts" in the left column of PdfTextWidgets.
After that, I had downloaded a full trial version, but it`s behavior is the same! If I create 1 large file (~100 pages) there is no any bug? but if I create 10 files ~ 10 pages in each of them, I have the same bug? as in free version. So, what can I do to solve my problem?

Here is my code:
Code: Select all

public static void CreatePages(string[] codes, PdfDocument doc)
        {
            var section = CreateSection(doc);
            PdfNewPage page = section.Pages.Add();
            var itemCount = 0;
            float h = 0;
            float w = 0;
            var countH = 0;
            var countW = 1;
            var pageCount = 1;
            var pdfCount = 1;
            var isSaved = true;
            try
            {
                foreach (var item in codes)
                {
                    isSaved = false;
                    var code = item.Replace(",", "");
                    var shortcode = "";
                    shortcode = item.Remove(0, 36);
                    shortcode = shortcode.Remove(GparseSym);
                    CreateImage(code);
                    code = code.Replace("/", "");
                    code = code.Replace("?", "");
                    code = code.Replace(":", "");
                    DrawImageQR(page, code + "_QRcode.png", h + Glmargin, w + Gtmargin); //0                 
                   
                    PdfTextWidget text = new PdfTextWidget
                    {
                        Font = new PdfFont(PdfFontFamily.Courier, 10, PdfFontStyle.Bold),
                        Text = shortcode                       

                    };
                    text.Draw(page, h + GtextH, w + GtextW); //h - text horizontal, w text vertical // 5 55
                   
                    w += Gintercol;
                    countH++;
                    if (countH == Gh)
                    {
                        w = 0;
                        h = countW * Ginterrow;
                        countW++;
                        countH = 0;
                    }
                    if (countW == Gw)
                    {
                        countW = 1;
                        countH = 0;
                        w = 0;
                        h = 0;
                        if (pageCount < 10)
                        {
                            if (itemCount < codes.Length - 1)
                            {
                                page = section.Pages.Add();
                                pageCount++;
                            }
                        }
                        else
                        {
                            doc.SaveToFile("PDFS\\Barcode_" + pdfCount + ".pdf");
                            doc.Close();
                            pdfCount++;
                            countW = 0;
                            countH = 0;
                            w = 0;
                            h = 0;
                            pageCount = 1;
                            doc = new PdfDocument();
                            if (itemCount < codes.Length)
                            {
                                section = CreateSection(doc);
                                page = section.Pages.Add();
                            }
                            isSaved = true;
                        }
                    }
                    itemCount++;
                                                                                     
                    Thread.Sleep(50);
                }

                if (!isSaved)
                {
                    doc.SaveToFile("PDFS\\Barcode_" + pdfCount + ".pdf");
                    doc.Close();                   
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
        }


min4er
 
Posts: 3
Joined: Tue Apr 11, 2017 12:59 pm

Wed Apr 12, 2017 8:58 am

Hello,

Thanks for your inquiry.
With a lot of missing methods and data in your code snippet, I can't reproduce the issue at my end. In order to help us have a better investigation and give you a quick solution, could you please share your complete data and the related methods(better to have the whole project)? You can both upload it here or send to us via email(support@e-iceblue.com).

Many Thanks,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Apr 13, 2017 7:17 am

Hello!
Please, look for sourse code at email!

min4er
 
Posts: 3
Joined: Tue Apr 11, 2017 12:59 pm

Thu Apr 13, 2017 9:16 am

Hello,
 
Thanks for sharing your C# solution via emial.
After an initial investigation, we found a mistake in your code. You had wrongly reset the value of countW to 0, so the barcode image and string will be drawn twice in the first column, thus causing the overlapping issue. To solve it, please change your code to "countW = 1;" at line 191 in BarcodeGenerator.cs
If there's still any problem, welcome to write back.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Apr 14, 2017 6:24 am

Thanks a lot, now it works fine!
Sad, but it was my own mistake.

min4er
 
Posts: 3
Joined: Tue Apr 11, 2017 12:59 pm

Fri Apr 14, 2017 8:25 am

Hello,

It's always my pleasure to help you.
Once there's any doubt in the future, do not hesitate to post.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF