Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:49:39+00:00 2026-06-09T10:49:39+00:00

I am using itextsharp and trying to use PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

  • 0

I am using itextsharp and trying to use

PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

which is a static method but I always get this error

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 178: 
Line 179:            //create a new action to send the document to our new destination.
Line 180:            PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);
Line 181:
Line 182:            //set the open action for our writer object


Source File: VoucherService.cs    Line: 180

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   iTextSharp.text.pdf.PdfWriter.GetPageReference(Int32 page) +326
   iTextSharp.text.pdf.PdfAction.GotoLocalPage(Int32 page, PdfDestination dest, PdfWriter writer) +49
   OnlineStudentPlanner.Framework.Services.VoucherService.SetupPdfDoc(String invoiceNumber, String logoPath, Document doc, MemoryStream memoryStream, PdfWriter writer, PdfPTable& table) in VoucherService.cs:180
   OnlineStudentPlanner.Framework.Services.VoucherService.GenerateVouchers(Int32 qty, Int32 voucherSize, String invoiceNumber, String logoPath, Int32 siteWideQty, IEnumerable`1 validDomains, Boolean siteWideVoucher) in VoucherService.cs:55
   OnlineStudentPlanner.WebUI.Areas.Admin.Controllers.HomeController.GenerateVouchers(GenerateVouchersVm vm) in Admin\Controllers\HomeController.cs:52
   lambda_method(Closure , ControllerBase , Object[] ) +163
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

here is my code that I have

Document doc = new Document();
MemoryStream memoryStream = new MemoryStream();
PdfPTable table;

doc.Open();

PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
writer.CloseStream = false;

SetupPdfDoc(invoiceNumber, logoPath, doc, memoryStream, writer, out table);

private  void SetupPdfDoc(string invoiceNumber, string logoPath, Document doc,  MemoryStream memoryStream, PdfWriter writer, out PdfPTable table)
{
    PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 0.75f);
    doc.AddTitle(String.Format("Vouchers-{0}", invoiceNumber));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:49:40+00:00Added an answer on June 9, 2026 at 10:49 am

    This is because you are trying to operate on an empty PDF document without any pages.

    Changing the following three lines:

            doc.Open();
    
            PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
            writer.CloseStream = false;
    

    to:

            PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
            writer.CloseStream = false;
            doc.Open();
            doc.NewPage();
    

    should resolve your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create Landscape PDF using iTextSharp but It is still showing
i am using itextsharp and i am trying to get all the fonts of
I am trying to extract all the images from a pdf using itextsharp but
I am trying to do something relatively simple with iTextSharp, but I always find
I'm currently using ITextSharp to write a PDF to a web browser, but I
I'm using itextsharp to generate the PDFs, but I need to change some text
I am trying to use iTextSharp to read/modify PDF metadata. I figured out how
Okay... I'm trying to use the most recent version of ITextSharp to turn an
I'm trying to save to databse a pdf file generated by itextsharp. But, I
I am trying to generate a PDF using iTextSharp. It will consists of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.