There is actually a (subtle) difference between the two. Imagine you have the following code in File1.cs:
// File1.cs
using System;
namespace Outer.Inner
{
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now imagine that someone adds another file (File2.cs) to the project that looks like this:
// File2.cs
namespace Outer
{
class Math
{
}
}
The compiler searches Outer
before looking at those using
directives outside the namespace, so it finds Outer.Math
instead of System.Math
. Unfortunately (or perhaps fortunately?), Outer.Math
has no PI
member, so File1 is now broken.
This changes if you put the using
inside your namespace declaration, as follows:
// File1b.cs
namespace Outer.Inner
{
using System;
class Foo
{
static void Bar()
{
double d = Math.PI;
}
}
}
Now the compiler searches System
before searching Outer
, finds System.Math
, and all is well.
Some would argue that Math
might be a bad name for a user-defined class, since there's already one in System
; the point here is just that there is a difference, and it affects the maintainability of your code.
It's also interesting to note what happens if Foo
is in namespace Outer
, rather than Outer.Inner
. In that case, adding Outer.Math
in File2 breaks File1 regardless of where the using
goes. This implies that the compiler searches the innermost enclosing namespace before it looks at any using
directive.
This is quick, easy, to the point and doesn't require any third-party script:
<embed src="http://example.com/the.pdf" width="500" height="375"
type="application/pdf">
UPDATE (2/3/2021)
Adobe now offers it's own PDF Embed API.
https://www.adobe.io/apis/documentcloud/dcsdk/pdf-embed.html
UPDATE (1/2018):
The Chrome browser on Android no longer supports PDF embeds. You can get around this by using the Google Drive PDF viewer
<embed src="https://drive.google.com/viewerng/
viewer?embedded=true&url=http://example.com/the.pdf" width="500" height="375">
Best Answer
The problem with using the
PdfReader.IsEncrypted
method is that if you attempt to instantiate aPdfReader
on a PDF that requires a password - and you don't supply that password - you'll get aBadPasswordException
.Keeping this in mind you can write a method like this:
Note that if you supply an invalid password you'll get the same
BadPasswordException
when attempting to construct aPdfReader
object. You can use this to create a method that validates a PDF's password:Sure it's ugly but as far as I know this is the only way to check if a PDF is password protected. Hopefully someone will suggest a better solution.