none
Correct the code RRS feed

  • Question

  • Hi,
    How to resolve issue like
    The type or namespace name 'PdfWriter' could not be found (are you missing a using directive or an assembly reference?)




    on codes below?


    using iText.StyledXmlParser;
    using iText.Forms.Xfdf;
    using iText.IO.Util;
    using iText.Layout.Layout;
    using iText.StyledXmlParser.Util;

    ... PdfWriter pdfWriter = new PdfWriter("test.pdf");




    Many Thanks & Best Regards, Jackson Chen



    Sunday, October 18, 2020 2:10 PM

Answers

  • Hi Jackson,

    Thank you for posting here.

    I think the PM Console you are talking about is the Package Manager Console, right?

    This is a way to add nuget packages, but more people may be more accustomed to using the view to add nuget packages.

    Right-click the project and select Manager nuget packages to open this view.

    Enter the name in the search box, you can find the relevant nuget package, and click the download button on the right side of the package to add it to your project.

    If you add iText7, add "using iText.Kernel.Pdf;" above the code, if you add iTextSharp, add "using iTextSharp.text.pdf;".

    But it is best not to use them at the same time, otherwise, you may encounter this error:

    If you want to get them in the Package Manager Console, you can refer to this link.

    You do not need to write the version, it will use the latest version by default.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jackson_1990 Monday, October 19, 2020 9:49 AM
    Monday, October 19, 2020 9:21 AM

All replies

  • Try using the iText7 documentation - iText.Kernel.Pdf.PdfWriter Class
    Sunday, October 18, 2020 2:36 PM
  • Hello,

    Most likely you don't have the right using statement. So you can type out the full path to PdfWriter to learn the proper namespaces. Or from the following Code Project article.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, October 18, 2020 2:39 PM
    Moderator
  • Karen,

    If I use iTextSharp instead, which reference (or DLL) should be used within VS 2017?


    Many Thanks & Best Regards, Jackson Chen


    Sunday, October 18, 2020 3:25 PM
  • Hi Jackson,

    If you go to the CodeProject link that Karen provided, you'll see an animated GIF that shows you how to add a reference to the itextsharp.dll to your project.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 18, 2020 6:07 PM
    Moderator
  • Karen,

    If I use iTextSharp instead, which reference (or DLL) should be used within VS 2017?


    Many Thanks & Best Regards, Jackson Chen


    Thought you were using ITextSharp, seems I was wrong so the question is what library is being used should had been indicated.

    So what you can do with your current code is figure out where PDFWriter comes from and that will solve the issue.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, October 18, 2020 6:58 PM
    Moderator
  • Hi Jackson,

    If you go to the CodeProject link that Karen provided, you'll see an animated GIF that shows you how to add a reference to the itextsharp.dll to your project.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Hi,
    What update do we need in PM Console, to have iTextSharp?


    Many Thanks & Best Regards, Jackson Chen

    Monday, October 19, 2020 3:29 AM

  • Hi,
    What update do we need in PM Console, to have iTextSharp?


    Many Thanks & Best Regards, Jackson Chen

    I'm sorry, Jackson ... I know nothing about iTextSharp other than the CodeProject link provided by Karen. I did not download the source code zip, so if PM Console is something that's in that source code, I suppose I could download it and see if I can help you. If PM Console is something else, then I have no idea what you're referring to. Sorry.  =0(

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Monday, October 19, 2020 4:32 AM
    Moderator
  • Hi,
    Could you help and check it if possible?

    Many Thanks & Best Regards, Jackson Chen

    Monday, October 19, 2020 5:09 AM
  • Hi Jackson,

    Thank you for posting here.

    I think the PM Console you are talking about is the Package Manager Console, right?

    This is a way to add nuget packages, but more people may be more accustomed to using the view to add nuget packages.

    Right-click the project and select Manager nuget packages to open this view.

    Enter the name in the search box, you can find the relevant nuget package, and click the download button on the right side of the package to add it to your project.

    If you add iText7, add "using iText.Kernel.Pdf;" above the code, if you add iTextSharp, add "using iTextSharp.text.pdf;".

    But it is best not to use them at the same time, otherwise, you may encounter this error:

    If you want to get them in the Package Manager Console, you can refer to this link.

    You do not need to write the version, it will use the latest version by default.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jackson_1990 Monday, October 19, 2020 9:49 AM
    Monday, October 19, 2020 9:21 AM
  • Hi,
    Thanks a lot.
    How to resolve

    The type or namespace name 'Document' could not be found (are you missing a using directive or an assembly reference?)



    due to last line below?

                PdfWriter pdfWriter = new PdfWriter("A0.pdf");
                PdfDocument pdfD0 = new PdfDocument(pdfWriter);
                Document D0 = new Document(pdfD0);
    


    Many Thanks & Best Regards, Jackson Chen

    Tuesday, October 20, 2020 5:12 AM
  • Hi Jackson,

    You can hover the mouse over the document, and then you will see a light bulb icon with a red error symbol, when you click on it, you will see the Intelli Sense of Visual Studio。

    In this case, choose the first one.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 20, 2020 6:07 AM