I am trying pdfDocument.GetPage(4).GetContentBytes()
but getting an error object reference not set to instance of an object.
itext kernel at kernel extension.get[tkey, tvalue]
But If I try pdfDocument.GetPage(5).GetContentBytes() it is working.
In comments you say:
I am creating a pdf from Json Data , after particular point need to read a particular content in pdf
so i am using this method pdfDocument.GetPage(4).GetContentBytes() to read it but not able to read the content in page 4
According to this you attempt to retrieve the content bytes of a page you have recently created in the same PdfDocument instance.
I assume you are creating the content in your PDF using a Document instance which you have created using either the single argument constructor:
/// <summary>
/// Creates a document from a <see cref="iText.Kernel.Pdf.PdfDocument"/>.
/// </summary>
/// <remarks>
/// Creates a document from a <see cref="iText.Kernel.Pdf.PdfDocument"/>.
/// Initializes the first page with the <see cref="iText.Kernel.Pdf.PdfDocument"/>'s
/// current default <see cref="iText.Kernel.Geom.PageSize"/>.
/// </remarks>
/// <param name="pdfDoc">the in-memory representation of the PDF document</param>
public Document(PdfDocument pdfDoc)
or the double argument constructor:
/// <summary>
/// Creates a document from a <see cref="iText.Kernel.Pdf.PdfDocument"/>
/// with a manually set <see cref="iText.Kernel.Geom.PageSize"/>.
/// </summary>
/// <param name="pdfDoc">the in-memory representation of the PDF document</param>
/// <param name="pageSize">the page size</param>
public Document(PdfDocument pdfDoc, PageSize pageSize)
Unfortunately for your use case both these constructors activate an optimization in the Document code which flushes the page data from memory to the target output stream as soon as possible after filling the next page has been started. (This optimization allows creating large PDFs with iText 7 while keeping the memory requirements small.)
In your case iText appears to already have flushed page 4 (resulting in your error) but not yet page 5 (so its content still could be retrieved).
If you need to access pages long after having started putting content onto the following page, you should instead use the triple argument Document constructor
/// <summary>
/// Creates a document from a <see cref="iText.Kernel.Pdf.PdfDocument"/>
/// with a manually set <see cref="iText.Kernel.Geom.PageSize"/>.
/// </summary>
/// <param name="pdfDoc">the in-memory representation of the PDF document</param>
/// <param name="pageSize">the page size</param>
/// <param name="immediateFlush">
/// if true, write pages and page-related instructions to the
/// <see cref="iText.Kernel.Pdf.PdfDocument"/> as soon as possible.
/// </param>
public Document(PdfDocument pdfDoc, PageSize pageSize, bool immediateFlush)
with an immediateFlush value of false.
Related
Is there a way to add custom tags for the summary in VisualStudio 2017 to see them in the IntelliSense?
I have an object HtReturnStatus which contains a HtErrorCode. There are around ~100 HtErrorCode in our library. So it would be an improovement for us if it would be possible to declare the error codes the method could return.
(If needed, ReSharper is available)
Info: https://learn.microsoft.com/de-de/dotnet/csharp/programming-guide/xmldoc/recommended-tags-for-documentation-comments
public class Foo
{
/// <summary>
/// This method returns error codes.
/// </summary>
/// <ErrorCodes>
/// <see cref="HtErrorCode.USER_WrongCredentials"/> / <see cref="HtErrorCode.USER_UserNotFound"/>
/// </ErrorCodes>
public static HtReturnStatus Login()
{
return HtReturnStatus.Failed(HtErrorCode.USER_WrongCredentials);
}
}
Hint
If you want to add custom tags in your XML documentation file, have a look at the solution from Peter Macej (https://stackoverflow.com/a/49757547/6229375)
Do you need the info about the error codes to be visible in IntelliSense or in generated documentation? If in IntelliSense, you should put it in some existing top level XML doc tag. The best seems <returns> to me. For example:
/// <summary>
/// This method returns error codes.
/// </summary>
/// <returns>
/// The <see cref="HtErrorCode"/> object with one of the following error codes:
/// <see cref="HtErrorCode.USER_WrongCredentials"/> or <see cref="HtErrorCode.USER_UserNotFound"/>.
/// </returns>
If that info is longer, I would put it inside <remarks> tag.
If you really want a separate top-level block as in your example, this can be done. But it will not be shown in Intellisense, only in generated documentation.
I don't know how about other tools, but our VSdocman (I'm the developer of it) supports exactly such custom tags.
I have a property which can be null. I want to documentate this in the summary and here is my problem.
cref
/// <summary>
/// Can be <see cref="null"/>.
/// </summary>
public object FooProperty;
ReSharper says, there is a Syntax Error, but the highlighting is working as expected!
cref nested
/// <summary>
/// Can be <see><cref>null</cref></see>.
/// </summary>
public object FooProperty;
When formating it to nested, the highligghting is not working anymore.
langword
/// <summary>
/// Can be <see langword="null"/>.
/// </summary>
public object FooProperty;
langword is working, but there is no intelliSense in VisualStudio.
Can someone please tell me what is the right way to documentate these keywords and IntelliSense support would be nice!
solution approach
VisualStudio | CodeSnippet for inside comment/summary block (IntelliSense)
The langword is the way to go. You are right, there's no Intellisense support for this. It's probably because it's not officially recommended XML comment tag attribute. But the tools that can generate documentation from your comments, e.g. Sandcastle Help File Builder or VSdocman (disclaimer, I'm the developer of VSdocman) will recognize this syntax and will generate a special text. For example, VSdocman generates:
null reference (Nothing in Visual Basic)
The same applies to other reserved words, such as true, abstract, etc.
While Intellisense will not help you, VSdocman has a WYSIWYG comment editor which can assist you with more complex comments.
One more note to <see cref="null"/>. This will create a link to the class, method or property named null. This is not directly possible in C#, where you need to prepend # before the name that is a reserved word:
/// <summary>
/// <see cref="#null"/>
/// </summary>
public class MyClass
{
public void #null() {}
}
But this is perfectly valid in VB .NET:
''' <summary>
''' <see cref="null"/>
''' </summary>
Public Class MyClass
ReadOnly Property null As String
End Class
At design time it can be helpful to jump back in code to a caller and vice versa especially when many files and windows are already open.
How can I create hyperlinks in my code or comments to navigate inside Visual Studio files?
e.g. like this:
// vs://CallingClassName.cs#methodeName()
// some further comments
Class AService1 {
}
If you have VS 2015, you can do it without any add-ins. I think it didn't work in earlier versions of VS. Just use standard XML doc comments with link elements: <see> or <seealso>. Here's an example with multiple ways for creating a link:
/// <summary>
/// My class description.
/// </summary>
/// <remarks>
/// See <see cref="CallingClassName.methodeName"/> for further details.
/// </remarks>
/// <seealso cref="CallingClassName.methodeName"/>
/// <seealso cref="CallingClassName.methodeName">A method with further details.</seealso>
Class AService1 {
}
If you just want to place a single link without any additional comments, I would prefer the <seealso> tag because it's a top level XML comment tag and it doesn't require a parent, such as <summary> or <remarks>.
Then just right click on the cref value and select "Go To Definition" or press F12. You will be navigated to the correct code element.
As a bonus, when you use XML comments, you'll get IntelliSense description and you can generate the class documentation with VSdocman (our product) or Sandcastle.
A WP 7.1 project starts with a Page that host a Panorama control. At some point user click on a ListBox, and this navigates the application to a details page.
In case the debugger is attached, everything stays on the screen as it should. But If I test an application either in emulator, or on the phone without a debugger, approximately in 5-10 seconds after the details page navigation, an application gets deactivated.
No unhanded exception, not closing, but deactivated even is raised. I have placed a message boxes in each of "exit handlers" to know exactly what happens and found out that it is deactivation.
No user input takes place after navigation and before the deactivation.
What may be the reason for such "no interaction" deactivation?
I don't call no "deactivate" requests from code.
Additional info:
Details page is bound to a sample view model that is obtained via MVVM Light ViewModel locator. View model locator gets it from ninject kernel that is a static public property of an App object(Yes, I have made IOC container publicly available via App property. I know it probably is a horrible practice, but I doubt the problem is linked to that). The page initializes just fine and displays all the data from a sample view model class. It almost seems like an app is deactivated due to inactivity, but there is no such thing in WP7 as far as I know.
UPDATE
A deactivation takes place exactly 10 seconds afer I call this line:
((PhoneApplicationFrame)(Application.Current.RootVisual)).Navigate(new Uri("/Views/BookDetailsView.xaml", UriKind.Relative));
from a view model of a main application view. The problem view is a details view, not the main one.
The constructor for BookDetailsView is empty (default):
public partial class BookDetailsView : UserControl
{
public BookDetailsView()
{
InitializeComponent();
}
}
The XAML for the view binds it's datacontext to a property of a mvvm light view model locator:
DataContext="{Binding Source={StaticResource Locator}, Path=BookDetails}"
The Locator resource is decleared in App.xaml and points to ViewModelLocator.cs.
The property that provides datacontext for a problem view is:
public static IBookDetailsViewModel BookDetailsStatic
{
get;
set;
}
/// <summary>
/// Gets the Main property.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
"CA1822:MarkMembersAsStatic",
Justification = "This non-static member is needed for data binding purposes.")]
public IBookDetailsViewModel BookDetails
{
get
{
return BookDetailsStatic;
}
}
The BookDetailsStatic is initialized from the IoC container call in the ViewModelLocator ctor:
BookDetailsStatic = App.Kernel.Get<IBookDetailsViewModel>();
In a any scenario the call to get an IBookDetailsViewModel returns an instance of a
public class SampleBookDetailsViewModel: IBookDetailsViewModel
which has an empty constructor and a bunch of properties.
SOLVED
My view, that I have been navigating to, was declared as a UserControl, and should have been as PhoneApplicationPage.
Hard to say without knowing what's on the page, but you could be hitting the memory limit.
In general, you can consider the memory limit to be 90mb, but you're better off checking DeviceStatus.ApplicationMemoryUsageLimit and DeviceStatus.ApplicationCurrentMemoryUsage and possibly displaying it on screen every half second or so to debug.
You can also try the profiler, assuming it doesn't affect the repro.
BookDetailsView was decleared as a UserControl.
Navigating to a UserControl deactivates an application in 10 seconds.
Changing the type of a view to PhoneApplicationPage solves the problem.
Is it possible to create an intellisense-like link to a class / class property / class method in a simple comment in Visual Studio 2010 (doing ASP.NET MVC 3 project but i guess that doesn't really matter)? Are there any free plugins for this functionality?
Let's say I have this code:
//Blahblahblah
//As you can see on its definition - [SomeClass.SomeProperty] - blahblahblah
//blahblahblah
SomeInstanceOfSomeClass.CallingSomethingUsingSomeProperty(42);
I want to click on [TableModelClass] which will either open new tab or switch to already opened one and scroll automatically to the definition of class/method/etc., as if you typed F12 on it anywhere else outside comments.
I suspect there must be some VS plugins out there in the Internet...been googling for a while...
You can't add a link to another type.method that will actually appear as a clickable link in your code.
However, you can use XML documentation comments to add a link to another type/method that will appear as a clickable link in the Object Browser, in the generated XML documentation file, or in any other documentation that you might generate from these comments using tools like Sandcastle.
The syntax is to use either the <see> or <seealso> tag, and specify the type/method you want to link to as the cref attribute.
For example:
/// <summary>This is a helper method to add two integer values together.
/// <para>
/// <see cref="System.Console.WriteLine(System.Int32)"/> for information
/// about how to display the results.
/// </para>
/// <seealso cref="MyClass.Subtract"/>
/// </summary>
public static int AddIntegers(int a, int b)
{
return (a + b);
}
Not sure if I understand you correctly, but in Visual Studio 2008/2010 you can use the built-in intellisense by simply using triple slashes ///. Ie:
/// <summary>
/// My method summary
/// </summary>
/// <param name="myParam">some text</param>
void MyFunction(int myParam)
{}
Is this what you are looking for?