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 ...
随机推荐
- Android开发 ---基本UI组件7 :分页功能、适配器、滚动条监听事件
效果图: 1.activity_main.xml 描述: 定义了一个按钮 <?xml version="1.0" encoding="utf-8"?> ...
- oracle中next_day()、last_day()函数解析
oracle中next_day()函数解析 Sql代码 当前系统时间的下一星期一的时间select next_day(sysdate,1) from dual NEXT_DAY(date,char ...
- python基础07_tuple_dict
tuple 元组 dict 字典 更详细参考:https://www.cnblogs.com/jin-xin/articles/7562422.html #!/usr/bin/env pyth ...
- mongodb初步使用体验
前言 Mongodb是一个非常有名的缓存数据库,和它名气相当的还有redis和hbase.笔者之前使用过redis,memcache和elasticsearch,借着工作机会,正好可以好好学习一下mo ...
- session_unset,session_destroy
session_unset()释放当前用户在内存中已经创建的所有$_SESSION变量,但不删除session文件以及不释放对应的sessionid session_destroy()删除当前用户对应 ...
- Java学习笔记36(jdbc快速入门)
JDBC: Java DataBase Connectivity 是java程序连接存取数据库的应用程序接口 (是sun公司的程序员定义的一套操作数据库的规则,然后下面的各个公司如:mysql,sql ...
- leetcode题解 5. Longest Palindromic Substring
题目: Given a string s, find the longest palindromic substring in s. You may assume that the maximum l ...
- 04_安装Nginx图片服务器
一.安装Nginx 先安装Nginx,看我之前发的文章: 搭建Nginx服务器 二.安装vsftpd 再安装vsftpd组件,看我之前发的文章: Linux安装ftp组件 三.开始搭建Nginx图片服 ...
- 【坑】https证书链不完整的坑
支付宝支付回调https失败,微信分享https连接在微信里打开空白,而chrome等浏览器访问正常. 是的,以上问题我作为半个运维在项目中遇到了,就是由于https证书链不完整引起的. 好吧,其实压 ...
- A New Function(LightOJ 1098)积性函数前缀和的应用
题意:要求对于1~n,每个数的约数(不包括1和其本身)的和. 题解:由于题目数据有2*10^9之大,因而不能直接暴力.需要考虑积性函数的特性,由于必定有重复的约数出现,因而可以对重复约数所在的区间进行 ...