I forget to mention that I' am using itextsharp 5.0.2.

It turned out that PDF DPI = 110, which means 110 pixels per inch, and since itextsharp uses points as measurment unit then :

  • n pixels = n/110 inches.
  • n inches = n * 72 points.

Having a helper method to convert pixels to points is all I needed:

public static float PixelsToPoints(float value,int dpi)
{
return value / dpi * 72;
}

By using the above formula and passing a dpi value of 110 it worked perfectly:

alt text http://www.freeimagehosting.net/uploads/1c8287b8d9.png

Note: Since you can create pdf documents in any size you want, this may lead to incorrect scaling when printing out your documents. To overcome this issue all you need to do is to have the correct aspect ratio between width and height [approximately 1:1.4142] (see : Paper Size - The international standard: ISO 216 ).

举个例子,有图片653*1636大小,生成PDF:所使用的尺寸应为,653/110 * 72 = 427.4,  1636/110 * 72 = 1070.8

 iTextSharp.text.Rectangle Rec = new iTextSharp.text.Rectangle(427.5f, 1070.8f);
//设置页面颜色
//Rec.BackgroundColor = new iTextSharp.text.BaseColor(0, 0, 0); Document doc = new Document(Rec, , , , ); try
{
PdfWriter writer = PdfWriter.GetInstance(doc,
new FileStream(@"C:\Us***\Images.pdf", FileMode.Create));
doc.Open();
doc.AddTitle("****相关电子资料");//标题
doc.AddSubject("申请审批文档");//主题
doc.AddKeywords("***表");//关键字
doc.AddAuthor("**软件");//作者
doc.AddCreationDate();//创建时间
doc.AddCreator("***管理系统");
writer.Info.Put(new PdfName("Producer"), new PdfString("江苏省**科技有限责任公司"));
Paragraph para = new Paragraph();
//para.IndentationLeft = 0f; //左缩进
doc.Add(para);
//foreach (string file in listBox1.Items)
{
doc.NewPage();
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(@"G:\***\Snap11.jpg");
//img.ScalePercent(100f);
img.ScaleAbsolute(Rec);
//img.SetDpi(200, 200);
//img.ScalePercent(72.0F / 96.0F * 100); img.Alignment = iTextSharp.text.Image.UNDERLYING;
img.SetAbsolutePosition(, );
doc.Add(img);
}
}
catch (DocumentException dex)
{
MessageBox.Show(dex.Message);
}
catch (IOException ioex)
{
MessageBox.Show(ioex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
doc.Close();
}

itextsharp图片生成pdf模糊问题解释的更多相关文章

  1. 使用 ItextSharp HTML生成Pdf(C#)

    以前生成pdf的时候.因为生成的pdf数据是固定的,所以先做好pdf模板,动态的数据可以先用占位符 生成的时候.找到占位符坐标.把数据填充进去 优点:先做好模板.生成的pdf 表格.文.内容会好看一些 ...

  2. iTextSharp简单生成pdf和操作pdf添加水印

    遇到需要导出页面到pdf,并添加pdf水印的业务.稍微研究了下,借阅网友的前车之鉴,经过使用可行之后的代码贴出来,做个记录,也供需要的网友借阅. public class PDFSetWaterMar ...

  3. NET二进制图片存储与读取的常见方法,iTextSharp添加图片生成PDF文件

    public void iTextSharpCreatPDF() { string pdfpath = System.Web.HttpContext.Current.Server.MapPath(&q ...

  4. 多图片生成pdf文件

    这里记录多个图片合并生成一个pdf文件的方法. 首先maven引入所需jar包: <dependency> <groupId>com.itextpdf</groupId& ...

  5. Java 图片生成PDF

    public static void main(String[] args) { String imageFolderPath = "E:\\Tencet\\图片\\test\\" ...

  6. 根据PDF模板生成PDF文件(基于iTextSharp)

    根据PDF模板生成PDF文件,这里主要借助iTextSharp工具来完成.场景是这样的,假如要做一个电子协议,用过通过在线填写表单数据,然后系统根据用户填写的数据,生成电子档的协议.原理很简单,但是每 ...

  7. vue实现pdf导出,解决生成canvas模糊等问题

    最近公司项目需要,利用vue实现pdf导出,从而保存到本地打印出来,说起来好像也很容易,具体要怎么实现呢? 1 .我们要添加两个模块 第一个.将页面html转换成图片 npm install --sa ...

  8. Javascript 将 HTML 页面生成 PDF 并下载

    最近碰到个需求,需要把当前页面生成 pdf,并下载.弄了几天,自己整理整理,记录下来,我觉得应该会有人需要 :) html2canvas 简介 我们可以直接在浏览器端使用html2canvas,对整个 ...

  9. js将 HTML 页面生成 PDF 并下载

    最近碰到个需求,需要把当前页面生成 pdf,并下载.弄了几天,自己整理整理,记录下来,我觉得应该会有人需要 :) 先来科普两个插件: html2Canvas 简介 我们可以直接在浏览器端使用html2 ...

随机推荐

  1. Mad Libs游戏 & 华氏温度与摄氏温度转换

    Mad Libs游戏 animal1 = input("请输入一种动物") animal2 = input("请输入一种动物") movement1 = inp ...

  2. 阶段01Java基础day22IO流03

    22.01_IO流(序列流) 1.什么是序列流 序列流可以把多个字节输入流整合成一个, 从序列流中读取数据时, 将从被整合的第一个流开始读, 读完一个之后继续读第二个, 以此类推. 2.使用方式 整合 ...

  3. noj装载问题

    描述 有两艘船,载重量分别是c1. c2,n个集装箱,重量是wi (i=1…n),且所有集装箱的总重量不超过c1+c2.确定是否有可能将所有集装箱全部装入两艘船.   输入 多个测例,每个测例的输入占 ...

  4. Spring Boot 常见标签

    @Controller(value=“名字”,descripation="描述",tags="具体" ) @RestController控制器(path=&qu ...

  5. 蓝牙协议分析(9)_BLE安全机制之LL Privacy

    1. 前言 在上一篇文章[1]中,我们介绍了BLE的白名单机制,这是一种通过地址进行简单的访问控制的安全机制.同时我们也提到了,这种安全机制只防君子,不防小人,试想这样一种场景: A设备表示只信任B. ...

  6. linux do{} while(0)

    do{}while(0) 在linux中,经常会看到do{}while(0)这样的语句,许多人开始都会疑惑,认为do{}while(0)毫无意义,因为它只会执行一次,加不加do{}while(0)效果 ...

  7. Linux命令行下:把程序放后台执行,以及从后台继续执行程序

    把任务放到后台用 & 和 Ctrl+z 让后台任务从停止状态转为运行状态用 bg %N 把后台任务调回到前台用 fg %N 查看所有任务用jobs

  8. 关于c风格的字符串的基本函数

    1.两个字符串的比较 //如果两个字符串相等 strcmp(s1,s2)=; //如果s1>s2 strcmp(s1,s2)>; //如果s1<s2 strcmp(s1,s2)< ...

  9. 渲染标签 - v-text

    <!DOCTYPE html><html><head>    <meta charset="utf-8">    <title ...

  10. 寒假作业pta3

    某地老鼠成灾,现悬赏抓老鼠,每抓到一只奖励10元,于是开始跟老鼠斗智斗勇:每天在墙角可选择以下三个操作:放置一个带有一块奶酪的捕鼠夹(T),或者放置一块奶酪(C),或者什么也不放(X).捕鼠夹可重复利 ...