图片看起来比实际大小的PDF

问题描述:

大,我有以下条码图像:图片看起来比实际大小的PDF

enter image description here

我使用以下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,然而,图像中出现大于预期,和失真:

enter image description here

我看不到任何地方,我将图像设置为特定尺寸,为什么它会像这样变形?我该如何预防它?

这个图像的大小保持原来的大小非常重要,以便条形码扫描仪可以读取它。

这里有一些事情正在进行,实际上他们中没有一个实际上与iText/iTextSharp有关。

首先,处理PDF内部的图像时总是考虑以英寸或厘米为单位,而不是像素。 300DPI的300像素图像为1英寸宽,72DPI的72像素图像也为1英寸宽。这两种图像在PDF中占据1英寸,前者只会有更多的像素塞进该空间,并可能看起来更好。这个非常重要。其次,使用上述信息,当您打印1“图像和的PDF不会缩放(Acrobat中的默认设置为适合哪些比例),您应该可以抓住标尺并精确测量1" 。

第三,我真的不知道Acrobat,Photoshop或其他程序认为“100%”是什么。在Acrobat中,如果您转到“编辑”,“首选项”,“页面显示”,您可以调整分辨率,并且更改的定义为100%。如果我将其改为90%,并用1“对象将其打印出来,它似乎与最接近的YMMV相匹配。我有一个想法,它应该应该的意思,但Adobe有明显不同的想法。