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 6638763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:29+00:00 2026-05-25T23:28:29+00:00

I am trying to use itextsharp to take dynamic information and generate a PDF

  • 0

I am trying to use itextsharp to take dynamic information and generate a PDF with it.. The PDF’s use a background Image on each page which is different and the text content is positioned where it needs to be using the contentByte helper. Thats the plan anyways. I hit a hang up when I tried to add another page and then drop the image and text onto that page… My first page ends up with the image that should be on my second page and the first page image fails to display at all on either page… My code so far is as follows:

                Function ID_and_Parking(ByVal id As Integer) As ActionResult
        Dim _reg_info As reg_info = db.reg_info.Single(Function(r) r.id = id)
        Dim _conf_info As conf_info = db.conf_info.Single(Function(f) f.id = 0)
        Dim _name As String = String.Empty


        If Not String.IsNullOrWhiteSpace(_reg_info.name_tag_pref) Then
            _name = _reg_info.name_tag_pref
        Else
            _name = _reg_info.first_name + " " + _reg_info.last_name
        End If
        Dim _LastName As String = _reg_info.last_name
        Dim _Employer As String = _reg_info.business_name
        Dim _Class_1 As String = _reg_info.tues_class
        Dim _Class_2 As String = _reg_info.wed_class
        Dim _Class_3 As String = _reg_info.thur_class
        Dim _Class_4 As String = _reg_info.fri_class
        Dim _BeginDate As String = _conf_info.conf_start_date
        Dim _endDate As String = _conf_info.conf_end_date
        Dim _dates As String = _BeginDate + "-" + _endDate

        If IsDBNull(_reg_info.tues_class) Then
            _Class_1 = ""
        End If
        If IsDBNull(_reg_info.wed_class) Then
            _Class_2 = ""
        End If
        If IsDBNull(_reg_info.thur_class) Then
            _Class_3 = ""
        End If
        If IsDBNull(_reg_info.fri_class) Then
            _Class_4 = ""
        End If


        Dim pdfpath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
        Dim imagepath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\PDF_Files\"
        Dim _PdfName As String = _LastName + ".pdf"
        Dim doc As New Document
        doc.SetPageSize(iTextSharp.text.PageSize.LETTER)
        doc.SetMargins(0, 0, 0, 0)

        Dim _PnameFont As iTextSharp.text.Font = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 18, iTextSharp.text.Font.NORMAL)
        Dim BF_Times As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, False)
        Dim _Parking_Name As New Font(BF_Times, 18, Font.NORMAL, BaseColor.BLACK)
        Dim _Parking_Date As New Font(BF_Times, 24, Font.BOLD, BaseColor.BLACK)



        Try
            Dim writer As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(pdfpath + _PdfName, FileMode.Create))
            doc.Open()


            Dim jpg As Image = Image.GetInstance(imagepath + "/Parking_Pass.jpg")
            jpg.Alignment = iTextSharp.text.Image.UNDERLYING
            jpg.ScaleToFit(612, 792)
            doc.add(jpg)
            Dim cb As PdfContentByte = writer.DirectContent
            'Render Parking Permit
            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 16)
            cb.SetTextMatrix(145, 135.5)
            cb.ShowText(_BeginDate)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 16)
            cb.SetTextMatrix(429, 135.5)
            cb.ShowText(_endDate)
            cb.EndText()



            Dim _idJpg As Image = Image.GetInstance(imagepath + "/Id_Tag.jpg")
            Dim imageWidth As Decimal = _idJpg.Width
            Dim imageHeight As Decimal = _idJpg.Height

            doc.SetPageSize(iTextSharp.text.PageSize.LETTER)


            _idJpg.Alignment = iTextSharp.text.Image.UNDERLYING
            _idJpg.ScaleToFit(612, 792)
            doc.NewPage()
            doc.Add(_idJpg)

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(100, 50)
            cb.ShowText(_name)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(200, 100)
            cb.ShowText(_Employer)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(300, 150)
            cb.ShowText(_Class_1)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(310, 50)
            cb.ShowText(_Class_2)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(320, 50)
            cb.ShowText(_Class_3)
            cb.EndText()

            cb.BeginText()
            cb.SetFontAndSize(BF_Times, 18)
            cb.SetTextMatrix(330, 50)
            cb.ShowText(_Class_4)
            cb.EndText()



            doc.Close()
        Catch dex As DocumentException
            Response.Write(dex.Message)
        Catch ioex As IOException
            Response.Write(ioex.Message)
        Catch ex As Exception
            Response.Write(ex.Message)



        End Try



        Return RedirectToAction("showUserPDF", New With {.pdfName = _PdfName})


    End Function

I have been all over every forum about this but all of the information I have found seems to be off from what I am looking for, OR maybe I am just going about this the wrong was all together… Any help would be greatly appreciated…

  • 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-05-25T23:28:29+00:00Added an answer on May 25, 2026 at 11:28 pm

    I actually have figured out the issue I overlooked my placement of the newpage and the image placement… I had the 2nd page image before the newpage… Thanks for your help… If anyone else neededs to dynamically fill a image with data the above solution works…

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

Sidebar

Related Questions

I am trying to use iTextSharp to read/modify PDF metadata. I figured out how
Trying to use an excpetion class which could provide location reference for XML parsing,
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
Okay... I'm trying to use the most recent version of ITextSharp to turn an
I have been trying use the edit_post_link() function to contain an image. All of
I'm trying to save to databse a pdf file generated by itextsharp. But, I
Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()
I'm trying to draw QR barcodes in a PDF file using iTextSharp. If I'm
I am trying use std::copy to copy from two different iterator. But during course
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()

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.