PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 10:21 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Mar 29, 2011 3:20 pm 
Offline

Joined: Tue Mar 29, 2011 3:16 pm
Posts: 1
I am following some sample code to fill out an AcroForm and get "A PDF name must start with a slash (/)"

Here is my code that was taken from the sample code (the sample throws the same error too)

using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.AcroForms;
using PdfSharp.Pdf.IO;


Code:
namespace Sandbox.PDFSharp
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string filePath = @"H:\Projects\Sandbox\Sandbox\PDFSharp\template_5.pdf";

            // Open the template
            PdfDocument template = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify);

            // Get the root object of all interactive form fields
            PdfAcroForm form = template.AcroForm;

            // Get all form fields of the whole document
            PdfAcroField.PdfAcroFieldCollection fields = form.Fields;

            // Get all form fields of the whole document
            string[] names = fields.Names;
            names = fields.DescendantNames;

            // Fill some value in each field
            for (int i = 0; i < names.Length; i++)
            {
                string fqName = names[i];
                PdfAcroField field = fields[fqName];

                PdfTextField txtField;


                if ((txtField = field as PdfTextField) != null)
                    txtField.Text = "Hello";
            }

            PdfDocument newDocument = new PdfDocument();

            // Save the document...
            const string filename = @"H:\Projects\Sandbox\Sandbox\PDFSharp\newDocument.pdf";
            newDocument.Save(filename);
        }
    }
}


It fails on names = fields.DescendantNames; with "A PDF name must start with a slash (/)."

Any ideas on what is wrong?

Thanks!
Neil


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 05, 2012 11:08 am 
Offline

Joined: Fri Oct 05, 2012 11:03 am
Posts: 1
Hi npc

I know it's a while since you posted your question, but I found if I commented out names = fields.DescendantNames; on line 91 of the FillFormFields.Program.cs file it seamed to work. Not too sure what that code was meant to do though.

Kind Regards,

Timothy Kruger


Top
 Profile  
Reply with quote  
PostPosted: Sun Jan 25, 2015 4:01 am 
Offline

Joined: Sun Jan 25, 2015 3:37 am
Posts: 5
yeah, the problem is it doesn't work.
I looked into it a bit and found that if there are no DescendantNames then it blows chunks with a message that makes no sense.
Considering I found this in the latest greatest 1.32ver in 2015 and you posted 2011 makes me wonder how it ever gets in the the "samples" folder.
FYI, don't bother trying the PDFviewerdemo sample either. It uses a namespace that doesn't exist.


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 74 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group