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. 《JavaScript Dom 编程艺术》读书笔记-第7章

    动态创建标记~内容包括: 1. 传统技术:document.write 和innerHTML 2. 深入剖析DOM方法:createElemen.createTextNode.appendChild和 ...

  2. makefile简单学习

    前言 在C语言中,我们需要将源代码生成可执行的程序.这里面其实要经过非常多的步骤.参看下图: 这中间主要通过make命令,读取一种名为“makefile”或“Makefile”的文件来实现软件的自动化 ...

  3. 写了一个Java的简单缓存模型

    缓存操作接口 /** * 缓存操作接口 * * @author xiudong * * @param <T> */ public interface Cache<T> { /* ...

  4. Windows+Linux双系统所导致的时间不一致问题的原因及解决方案

    参考自:https://www.cnblogs.com/x_wukong/p/4401499.html 前几天在自己的windows10另外还装了一个Ubuntu,使用后发现windows时间一直不对 ...

  5. Python pip源更改

    将pip源设置为阿里源 windows 打开文件资源管理器(文件夹地址中) 地址栏上面输入 %appdata% 在这里面新建一个文件夹pip 在pip文件夹里面新建一个文件叫做 pip.ini,内容如 ...

  6. SignalTap导致PCIe Read/Write卡死

    /********************************************************************** * SignalTap导致PCIe Read/Write ...

  7. mod_conference ESL控制三(程序)

    第一篇描述了mod_conference控制原理,第二篇描述了conference相关事件,接下来对esl内联程序做简要说明. 由于event-socket采用TCP协议,因此需要一个线程与frees ...

  8. Windows7下安装python3.6.3

    官网下载即可!看清自己的电脑是32还是64! 分享一个网速慢同学可下载网址:https://pan.baidu.com/s/1kU5OCOB#list/path=%2Fpub%2Fpython 1.p ...

  9. excle中如何将一串数字前后加上单引号

    1.新建excle表 2.构造如下一串字母加数字的字符串: 3.在B1栏中输入="“"&A1&"”",展示效果如下:

  10. 使用fpm 方便快速生成postgresql extension分发包

    fpm 是一个不错,而且强大的rpm.deb,系统启动服务工具包,我们可以用来快速的生成专业的软件分发包 演示一个pg 扩展包分发包的生成(rpm 以及deb) 安装fpm sudo gem inst ...