PDFsharp & MigraDoc Forum
https://forum.pdfsharp.net/

Assistance Please
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2110
Page 1 of 1

Author:  DT777 [ Thu Aug 16, 2012 5:00 pm ]
Post subject:  Assistance Please

So, I hacked together a program recently, designed to put together a pdf composed of 3.5x2 Business cards (10 to a sheet) for printing. I did this using abcPDF by WebSuperGoo at the direction of my employer.

Well, it turns out that the client doesn't like to use .dlls that require installed licenses. Their server admin pointed us to PDFsharp, I'm assuming because the OpenSource license doesn't cause trouble if you have to migrate servers. Whatever their reasoning, I now have to scrap my old code and write mostly new code.

Code:
 private static void singleton(Doc nProgress, PDFTable nTable, int position, String name, bool isPTA, String license, String expireDate, String[] fieldNames)
        {
            XImage cardImage = new XImage();
            String temp = System.Web.HttpContext.Current.Server.MapPath("Singleton.jpg");
            cardImage.SetFile(temp); //edit this with the path for the card image.
            nTable.AddImage(temp, cardImage, false, false);
          //  nTable.AddImage(cardImage, false);
            int currentPoint = position * 4;
            for (int x = 0; x < 4; x++)
            {
                Field editing = nProgress.Form[fieldNames[currentPoint]];
                switch (x)
                {
                    case 0: editing.Value = name;
                        break;
                    case 2: editing.Value = license;
                        break;
                    case 3: editing.Value = expireDate;
                        break;
                    case 1: if (isPTA)
                        {
                            editing.Value = "is Licensed as a Physical Therapist Assistant";
                        }
                        else
                        {
                            editing.Value = "is Licensed as a Physical Therapist";
                        }
                        break;
                    default:
                        break;
                }
                currentPoint++;
            }
            return;
        }

        public static String PrintSingle(int position, String name, String license, String expireDate, bool isPTA)
        {
            Doc toPrint = new Doc();
            toPrint.Read(System.Web.HttpContext.Current.Server.MapPath(blankPath));
            toPrint.Rect.Top = 756;
            toPrint.Rect.Bottom = 36;
            toPrint.Rect.Left = 36;
            toPrint.Rect.Right = 576;
            PDFTable theTable = new PDFTable(toPrint, 2);
            theTable.SetColumnWidths(new double[] {252, 252});
           
            for (int y = position / 2; y >= 0; y--)
            {
                theTable.NextRow();
                theTable.NextCell();
                XImage cardImage = new XImage();
                String temp = System.Web.HttpContext.Current.Server.MapPath("FillerImage.jpg");
                cardImage.SetFile(temp); //edit this with the path for the card image.
                theTable.AddImage(temp, cardImage, false, false);
                //theTable.AddImage(cardImage, false);
            }
            String[] fieldnames = toPrint.Form.GetFieldNames();
            Array.Sort(fieldnames);
            if (position % 2 == 1)
            {
                theTable.NextCell();
            }
            singleton(toPrint, theTable, position, name, isPTA, license, expireDate, fieldnames);
            toPrint.Flatten();
            toPrint.Save(savePath);

            return savePath;
        }


That above is my code. I was taking a blank PDF filled with fields (for Name, license no., etc), finding out where on the PDF I needed to start my printing, etc.

I guess what I'm asking is, is there functionality in PDFsharp similar to what abcPDF does? If so, can someone point me in the direction I should start?

Author:  () => true [ Sun Aug 19, 2012 8:39 pm ]
Post subject:  Re: Assistance Please

DT777 wrote:
is there functionality in PDFsharp similar to what abcPDF does?
I don't know. I never dealt with AcroForms.

I'd use MigraDoc (comes with PDFsharp) to create a table, one cell for each business card, and fill these table cells with paragraphs as needed.

It seems your code snippet relies on a PDF file with some form fields as a template. If there are labels or other text, you have to add that from MigraDoc along with the variable, personalized text.

PDFsharp has support for AcroForm fields, but I never played with that and cannot say your approach will work with PDFsharp, too (but likely it will).

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/