大,我有以下條碼圖像:圖片看起來比實際大小的PDF
我使用以下iTextSharp的VB.NET腳本生成含有該條形碼的PDF文檔:
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()
當產生此PDF,然而,圖像中出現大於預期,和失真:
我看不到任何地方,我將圖像設置爲特定尺寸,爲什麼它會像這樣變形?我該如何預防它?
這個圖像的大小保持原來的大小非常重要,以便條形碼掃描儀可以讀取它。