PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Thu Oct 02, 2025 5:25 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Assistance Please
PostPosted: Thu Aug 16, 2012 5:00 pm 
Offline

Joined: Thu Aug 16, 2012 4:50 pm
Posts: 1
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assistance Please
PostPosted: Sun Aug 19, 2012 8:39 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 354
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).

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 215 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group