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 ...
随机推荐
- 原生js手风琴效果
//js代码 //获取li var list = document.getElementsByTagName("li")[0]; //遍历 排他 for( var i=0;i&l ...
- LeetCode 257 二叉树的所有路径
题目: 给定一个二叉树,返回所有从根节点到叶子节点的路径. 说明: 叶子节点是指没有子节点的节点. 示例: 输入: 1 / \ 2 3 \ 5 输出: ["1->2->5&quo ...
- 补码的来源以及为什么byte的最小值是-128
1. 有符号数和无符号数 我们的实数分为正数和负数和0三部分 Byte数据类型一共有8位,如果是无符号数,最大可以表示的数为11111111 = 256 -1 = 255 无符号数代指不 ...
- 《JavaScript Dom 编程艺术》读书笔记-第4章
我的前端入门第一本书是<JavaScript Dom 编程艺术>,网上查找资料发现前端的入门推荐书籍最受好评的就是这本和<JavaScript 高级程序设计>了.之所以先选这本 ...
- numpy.where() 用法详解
numpy.where (condition[, x, y]) numpy.where() 有两种用法: 1. np.where(condition, x, y) 满足条件(condition),输出 ...
- winform 写入txt
StreamWriter sw; FileStream fs = new FileStream(@"D:\" + txtStringfield03.Text + ".tx ...
- 2019-04-10-day029-粘包处理
内容回顾 osi五层协议 不是真实存在的,只是抽象出来的模型 应用层 传输层 TCP/UDP TCP :全双工,可靠的,面向连接的,速度慢,对数据大小没有限制 建立连接 :三次握手 SYN ACK 断 ...
- Task使用
Task task1 = Task.Factory.StartNew(() => { Console.WriteLine("Hello,task started by task fac ...
- Ubuntu16.04 安装 MySQL
本篇介绍如何在Ubuntu系统上安装MySQL数据库,以及介绍数据库的基本命令. 一.下载和安装MySQL 可以通过apt-get下载并安装 sudo apt-get install mysql-se ...
- vim分屏操作
启动分屏 1.使用大写O参数进行垂直分屏 $ vim -On file1 file2 ... 2.使用小写o参数进行水平分屏 $ vim -on file1 file2 ... 注: n是数字,表示分 ...