Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Mar 07, 2023 4:41 pm

Hi, just installed FreeSpire.pdf and my code:
using Spire.Pdf;
namespace Oursystem.Tests.Reports
{
public class PubPDF
{
static string filename = "myreport.pdf";
string filepath = "C:\\documents\\myreport.pdf";

PdfDocument doc= new PdfDocument();
doc.LoadFromFile(filepath);

Issue: I'm getting compile error:
Severity Code Description Project File Line Suppression State
Error IDE1007 The name 'doc.LoadFromFile' does not exist in the current context. Tests C:\Tests\Reports\PubPDF.cs 14 Active
Error IDE1007 The name 'doc' does not exist in the current context. Tests C:\Tests\Reports\PubPDF.cs 14 Active

I uninstall/reinstall, and update-install from nuget manager, but can't call any of methods from PdfDocument doc

Anyone had this kind of issue, please help us. Thank you

hannahchoi
 
Posts: 1
Joined: Tue Mar 07, 2023 12:55 pm

Wed Mar 08, 2023 8:10 am

Hi,

Thank you for sharing the code snippet. Initializing a variable and calling a method directly within a class definition is not valid. They should be initialized in a method body or constructor instead.
Please see the following code for reference
Code: Select all
namespace Oursystem.Tests.Reports
{
    public class PubPDF
    {
        private string filename = "myreport.pdf";
        private string filepath = "C:\\documents\\myreport.pdf";

        public void TestLoadFile()
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(filepath);

            // TODO
        }
    }
}

If you have any other questions related to our products, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF

cron