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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:16:00+00:00 2026-05-26T23:16:00+00:00

I have the following barcode image: I’m using the following iTextSharp VB.NET script to

  • 0

I have the following barcode image:

enter image description here

I’m using the following iTextSharp VB.NET script to generate a PDF document containing this barcode:

Dim pdfDocument As iTextSharp.text.Document = Nothing

Dim filename As String = HttpContext.Current.Server.MapPath("barcode.pdf")

pdfDocument = New iTextSharp.text.Document()
Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, New FileStream(filename, FileMode.Create))

pdfDocument.Open()

Dim cb As iTextSharp.text.pdf.PdfContentByte = writer.DirectContent

pdfDocument.NewPage()

Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("barcode.jpg"))
pdfDocument.Add(img)

pdfDocument.Close()

Dim fInfo As New FileInfo(filename)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(filename, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data As Byte() = br.ReadBytes(CInt(numBytes))

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.AddHeader("Content-Type", "binary/octet-stream")
HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=barcode.pdf;size ={0}", data.Length.ToString()))
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.BinaryWrite(data)
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()

When this PDF is generated, however, the image is appearing larger than expected, and is distorted:

enter image description here

I can’t see anywhere where I’m setting the image to be a specific size, so why would it distort like this? And how can I prevent it?

It’s crucial that this image remains the size it is intended to be so that it can be read by barcode scanners.

  • 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-26T23:16:01+00:00Added an answer on May 26, 2026 at 11:16 pm

    There’s a couple of things going on here and none of them actually have to do with iText/iTextSharp actually.

    First, when dealing with images inside of a PDF always think in terms of inches or centimeters and never just pixels. A 300 pixel image at 300DPI is 1 inch wide and a 72 pixel image at 72DPI is also 1 inch wide. Both images will occupy 1 inch within the PDF, the former will just have more pixels to cram into that space and potentially look better. This is very important.

    Second, using the above information, when you print a PDF with a 1″ image and do not scale it (the default in Acrobat is to Fit which scales) you should be able to grab a ruler and measure exactly 1″.

    Third, I seriously don’t know what Acrobat, Photoshop or any other program consider “100%”. In Acrobat, if you go to Edit, Preferences, Page Display you can adjust the Resolution and that change’s the definition of 100%. If I change this to 90% and hold my printout with a 1″ object on it it seems to match the closest. YMMV.

    This third thing I think is your problem, mainly what “100%” means. You and I have an idea of what it should mean but Adobe has a different idea apparently.

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

Sidebar

Related Questions

I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following date: 2005-08-11T16:34:33Z I need to know if this is date is
I have the following query: DECLARE @str VARCHAR(500) SET @str = 'Barcode: 22037 CaseSize:
I have a select statement showing the following results: On_loan barcode Y 12345 Y
I have following structure of an HTML document: <body> <div class=main> <div class=left></div> <div
I have following code for an autocomplete box, I'm adding an image for choice
I have following script and it works fine with FF and Safari. function swapimage(cid)
I have following class. In this, Iris is another class with some attributes. public
I have following table it shows like this: ABC A B C 123 Hello
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.