0

I'm using the Aspose lib to convert a PDF file to Excel file, my code below:

using Aspose.Pdf;

public async Task convertPDFtoEXCEL(Document pdfFile, string root, string fileName)
{
    // Initialize ExcelSaveOptions
    ExcelSaveOptions opts = new ExcelSaveOptions();

    // Set output Excel XLSX format
    opts.Format = ExcelSaveOptions.ExcelFormat.XLSX;

    // Minimize number of Worksheets
    opts.MinimizeTheNumberOfWorksheets = true;

    // Convert PDF to Excel output file
    pdfFile.Save(root + fileName + ".xlsx", opts);
}

public async Task<int> Get()
{
    int number = 0;
    string root = "C:/Users/Downloads/";
    string fileName = "myFile";

    // load the PDF file                    
    Document pdfFile = new Document(root + fileName + ".pdf");

    // convert the PDF file to EXCEL
    await convertPDFtoEXCEL(pdfFile, root, fileName);

    // ...
    return number;
}

When my code ran I got this error:

System.InvalidOperationException: 'A model description could not be created. Duplicate model name 'Element' was found for types 'Aspose.Pdf.Structure.Element' and 'Aspose.Pdf.LogicalStructure.Element'. Use the [ModelName] attribute to change the model name for at least one of the types so that it has a unique name.'

What is the problem, and how can I fix it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Miriam F.
  • 21
  • 1
  • 7
  • 1
    Is code failing on pdfFile.Save() or convertPDFtoEXCEL()? You have duplicate data in either the excel or pdf and the names has to be changed so you do not have any duplicates. – jdweng Aug 20 '23 at 08:33
  • Hi jdweng, First thanks for your comment. 1. I can't see where the error is coming from, I don't get stopped at any break point, Immediately throws the error. 2. I don't have duplicates. 3. The error seems to come from the reference (aspose.pdf) do you have any idea with this? – Miriam F. Aug 20 '23 at 08:52
  • Then error is not in the code posted. Error must be captured in the library with an exception and then "throw" is not used so you cannot capture with your code. It looks like you have duplicate names so I would start by getting a list of the names and properties : https://docs.aspose.com/pdf/net/pdf-file-metadata/ – jdweng Aug 20 '23 at 09:17
  • FYI - when I changed the methods to be sync instead of Async, it worked! It's strange to me, But anyway, now it's good for me. Thanks. – Miriam F. Aug 20 '23 at 13:19
  • 1
    Would you please create a post in our official Aspose.PDF support forum (https://forum.aspose.com/c/pdf) as this issue needs more investigation. Please note that it is the recommended place to post and start such discussions. You can share your files securely as well. Please create a post there so that we can further proceed to investigate. This is Asad Ali and I work as Developer Evangelist at Aspose. – Asad Ali Aug 20 '23 at 18:20

0 Answers0