locked
Issue to PageSize RRS feed

  • Question

  • Hi,
    Any help to

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



    on this?
                Document D0 = new Document(pdfD0, new PageSize(298f, 178f));



    Many Thanks & Best Regards, Jackson Chen

    Saturday, October 24, 2020 3:33 PM

All replies

  • As the error message says, you may be missing a using directive.

    If you are trying to work with an OpenXml document, you need

    using  DocumentFormat.OpenXml.Wordprocessing;

    But it could be something else if you are working on a different type of objects. It cannot be inferred with certainty by just looking at that single line of code.

    If the reference to the assembly is already added to the project, Visual Studio is usually able to suggest the namespace that you are missing. Click on the little lightbulb that appears when you hover the mouse pointer around the word that produces the error, and Visual studio will offer to either add the missing directive or prepend the namespace to the class name.

    Saturday, October 24, 2020 5:06 PM
  • Which directive should be used? I cannot refer to "DocumentFormat..." now.

    Many Thanks & Best Regards, Jackson Chen


    Sunday, October 25, 2020 3:44 AM
  • It is not possible to know what directive should be used without knowing which is the class that you are trying to call. In other words, which library you are referencing and what functionality in that library you are trying to use. Armed with this information, you go into the documentation for such library and it should tell you which namespace they are using. Then you take that namespace and put it into your directive.

    Or simply use the trick of letting Visual Studio suggest the namespace to you. This will work as long as the library is already present in the References of the project. If it is not present, it will not work regardless of any directives that you use.

    Sunday, October 25, 2020 7:35 AM
  • I assume this is a continuation of your earlier questions related to using iTextSharp. As mentioned in those threads bear in mind that any sample code you mind find might be for iTextSharp, not iText7 which is what you should be using now. Therefore you need to change namespace references from `iTextSharp` to `iText`.

    For most types you can simply refer to the documentation as it tells you all this information already. PageSize is documented here. In that documentation it says the namespace is `iText.Kernel.Geom`. Add a using statement at the top of your code for this namespace just like you already have for `iText.Kernel` in order to get access to the other types.


    Michael Taylor http://www.michaeltaylorp3.net

    Sunday, October 25, 2020 3:24 PM
  • Why bother to read documentation when its so much easier to post a question and have someone else do the work?

    The OP has posted a series of questions that all have the same theme

    The type or namespace name <insert current problem> could not be found (are you missing a using directive or an assembly reference?)
    Sunday, October 25, 2020 4:23 PM