Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: cannot read PDF-form #466

Closed
svi7110 opened this issue Jun 27, 2022 · 2 comments
Closed

Error: cannot read PDF-form #466

svi7110 opened this issue Jun 27, 2022 · 2 comments
Labels

Comments

@svi7110
Copy link

svi7110 commented Jun 27, 2022

Hello,

if i try to extract Information from a form there is no form found. Is there any restriction in processing a pdf?

using System;
using System.Linq;
using UglyToad.PdfPig;
using UglyToad.PdfPig.AcroForms;
using UglyToad.PdfPig.AcroForms.Fields;

namespace ConsoleApp1
{
    internal class Program
    {
        public static void Run(string filePath)
        {
            using (var document = PdfDocument.Open(filePath))
            {
                bool hasForm = document.TryGetForm(out AcroForm form); // here i get false 
                if (!document.TryGetForm(out var form2))
                {
                    Console.WriteLine($"No form found in file: {filePath}.");
                    return;
                }
                var page1Fields = form.GetFieldsForPage(1);

                foreach (var field in page1Fields)
                {
                    switch (field)
                    {
                        case AcroTextField text:
                            Console.WriteLine($"Found text field on page 1 with text: {text.Value}.");
                            break;
                        case AcroCheckboxesField cboxes:
                            Console.WriteLine($"Found checkboxes field on page 1 with {cboxes.Children.Count} checkboxes.");
                            break;
                        case AcroListBoxField listbox:
                            var opts = string.Join(", ", listbox.Options.Select(x => x.Name));
                            Console.WriteLine($"Found listbox field on page 1 with options: {opts}.");
                            break;
                    }
                }
            }
            
        }
        static void Main(string[] args)
        {
            Run("D:\\test.pdf");

            
        }
    }
}
@EliotJones
Copy link
Member

Hi there's no restrictions on pulling content from PDFs with this library, are you able to share the file with the issue, it's likely an edge-case/non-conformant file that needs additional code to support it.

@svi7110
Copy link
Author

svi7110 commented Jul 3, 2022

Im cannot share but i think i know why this problem occured. I think the testing person printed his pdf. So it could be possible the file was flattened and the form objects has been cleared.
Tests with other files were successfully.
Thanks for your reply

@svi7110 svi7110 closed this as completed Jul 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants