itextsharp图片生成pdf模糊问题解释
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模糊问题解释的更多相关文章
- 使用 ItextSharp HTML生成Pdf(C#)
以前生成pdf的时候.因为生成的pdf数据是固定的,所以先做好pdf模板,动态的数据可以先用占位符 生成的时候.找到占位符坐标.把数据填充进去 优点:先做好模板.生成的pdf 表格.文.内容会好看一些 ...
- iTextSharp简单生成pdf和操作pdf添加水印
遇到需要导出页面到pdf,并添加pdf水印的业务.稍微研究了下,借阅网友的前车之鉴,经过使用可行之后的代码贴出来,做个记录,也供需要的网友借阅. public class PDFSetWaterMar ...
- NET二进制图片存储与读取的常见方法,iTextSharp添加图片生成PDF文件
public void iTextSharpCreatPDF() { string pdfpath = System.Web.HttpContext.Current.Server.MapPath(&q ...
- 多图片生成pdf文件
这里记录多个图片合并生成一个pdf文件的方法. 首先maven引入所需jar包: <dependency> <groupId>com.itextpdf</groupId& ...
- Java 图片生成PDF
public static void main(String[] args) { String imageFolderPath = "E:\\Tencet\\图片\\test\\" ...
- 根据PDF模板生成PDF文件(基于iTextSharp)
根据PDF模板生成PDF文件,这里主要借助iTextSharp工具来完成.场景是这样的,假如要做一个电子协议,用过通过在线填写表单数据,然后系统根据用户填写的数据,生成电子档的协议.原理很简单,但是每 ...
- vue实现pdf导出,解决生成canvas模糊等问题
最近公司项目需要,利用vue实现pdf导出,从而保存到本地打印出来,说起来好像也很容易,具体要怎么实现呢? 1 .我们要添加两个模块 第一个.将页面html转换成图片 npm install --sa ...
- Javascript 将 HTML 页面生成 PDF 并下载
最近碰到个需求,需要把当前页面生成 pdf,并下载.弄了几天,自己整理整理,记录下来,我觉得应该会有人需要 :) html2canvas 简介 我们可以直接在浏览器端使用html2canvas,对整个 ...
- js将 HTML 页面生成 PDF 并下载
最近碰到个需求,需要把当前页面生成 pdf,并下载.弄了几天,自己整理整理,记录下来,我觉得应该会有人需要 :) 先来科普两个插件: html2Canvas 简介 我们可以直接在浏览器端使用html2 ...
随机推荐
- ajax 请求问题
1.ajax 请求锁定页面加载 function agree(id,index){ var yj=$("#taskTableId tr[data-index='"+index+&q ...
- servlet运行“/*”引起的java.lang.StackOverflowError
<servlet> <servlet-name>login</servlet-name> <servlet-class>com.jd.login.UI. ...
- Redis在Linux系统下的安装和启动
详情可参见:https://blog.csdn.net/q1035331653/article/details/79077260 开机自启脚本参见:https://www.cnblogs.com/si ...
- 神州数码静态路由及直连网段引入到RIP协议配置(路由重定向)
实验要求:掌握静态路由及直连网段引入协议当中的配置 拓扑如下 R1 enable 进入特权模式 config 进入全局模式 hostname R1 修改名称 interface g0/6 进入端口 i ...
- MySQL配置文件my.ini或my.cnf的位置
1.Windows下MySQL的配置文件是my.ini,一般会在安装目录的根目录. 2.Linux下MySQL的配置文件是my.cnf,一般会放在/etc/my.cnf,/etc/mysql/my.c ...
- scrapy框架之递归解析和post请求
递归爬取解析多页页面数据 scrapy核心组件工作流程 scrapy的post请求发送 1.递归爬取解析多页页面数据 - 需求:将糗事百科所有页码的作者和段子内容数据进行爬取切持久化存储 - 需求分析 ...
- Cortex-M3 跳转到指定bin执行
跳转前指定sp和msp: #if defined(__GNUC__) __attribute__(( naked )) static void set_sp(unsigned long addr) { ...
- 后台获取用户登录token 和获取前端参数方法
//获取request请求中所有参数 Enumeration<String> names = request.getParameterNames(); HashMap<String, ...
- APPlication,Session和Cookie的区别
方法 信息量大小 保存时间 应用范围 保存位置 Application 任意大小 整个应用程序的生命期 所有用户 服务器端 Session 小量,简单的数据 用户活动时间+一段延迟时间(一般为20分钟 ...
- CCF-权限查询-201612-3
这道题,开始只有10分.....原因是将false 写成了 flase 我要吐血而亡....关键是还debug了半天,以为是逻辑错了 不过亮点是代码很简洁,网上140+的代码看着真复杂 核心: 做题之 ...