花了一些时间将PDF对象也整理好了!

hackztx 2008-06-12 09:03:54
 public static void CreateFile(string strFile, bool blTriggerThrow)
{
if (File.Exists(strFile) && blTriggerThrow)
{
throw new Exception(ErrorString.strFileOn);
}
File.Create(strFile);
}

/// <summary>
/// 删除文件
/// </summary>
/// <param name="strFile">文件地址</param>
public static void DeleteFile(string strFile)
{
if (!File.Exists(strFile))
{
throw new Exception(ErrorString.strFileOff);
}
File.Delete(strFile);
}

/// <summary>
/// 重命名文件
/// </summary>
/// <param name="strFile">传入文件地址</param>
/// <param name="strName">输入新的文件名</param>
public static void RenameFile(string strFile, string strName)
{
File.Move(strFile, Path.GetDirectoryName(strFile) + "//" + strName);
}

/// <summary>
/// 清空文件
/// </summary>
/// <param name="strFile">传入文件地址</param>
public static void TruncateFile(string strFile)
{
DeleteFile(strFile);
CreateFile(strFile, false);
}

/// <summary>
/// 复制文件
/// </summary>
/// <param name="strFile">传入文件地址</param>
/// <param name="strFile2">传入目标文件地址</param>
public static void CopyFile(string strFile, string strFile2)
{
File.Copy(strFile, strFile2);
}
/// <summary>
/// 内部私有对象给Image赋值
/// </summary>
/// <param name="strAlt">传入图片描述</param>
/// <param name="width">长度(如果为0那么使用图片本身的长度)</param>
/// <param name="hegiht">高度(如果为0那么使用图片本身的高度)</param>
/// <param name="x">X轴距离</param>
/// <param name="y">Y轴距离</param>
/// <param name="rotation">旋转度数</param>
/// <param name="align">图片对其方式</param>
private static void SetImage(string strAlt, float width, float hegiht, float x, float y, float rotation, int align, ref Image img)
{
img.Alt = strAlt;
if (width <= 0)
{
img.ScaleAbsoluteWidth(img.Width);
}
else
{
img.ScaleAbsoluteWidth(width);
}
if (hegiht <= 0)
{
img.ScaleAbsoluteHeight(img.Height);
}
else
{
img.ScaleAbsoluteHeight(hegiht);
}
if (x != 0 || y != 0)
{
img.SetAbsolutePosition(x, y);
}
else
{
img.Alignment = align;
}
img.Rotation = rotation;

}

/// <summary>
/// 返回一个基本的图片对象
/// </summary>
/// <param name="strImg">传入图片地址</param>
/// <param name="strAlt">传入图片描述</param>
/// <param name="width">长度高度(如果为0那么使用图片本身的长度)</param>
/// <param name="hegiht">高度高度(如果为0那么使用图片本身的高度)</param>
/// <param name="x">X轴距离</param>
/// <param name="y">Y轴距离</param>
/// <param name="rotation">旋转度数</param>
/// <param name="align">图片对其方式</param>
/// <returns></returns>
public static Image GetImages(string strImg, string strAlt, float width, float hegiht, float x, float y, float rotation, Alignment align)
{
Image img = Image.GetInstance(strImg);
SetImage(strAlt, width, hegiht, x, y, rotation, (int)align, ref img);
return img;
}

/// <summary>
/// 返回一个基本的图片对象
/// </summary>
/// <param name="strImg">传入图片字节</param>
/// <param name="strAlt">传入图片描述</param>
/// <param name="width">长度高度(如果为0那么使用图片本身的长度)</param>
/// <param name="hegiht">高度高度(如果为0那么使用图片本身的高度)</param>
/// <param name="x">X轴距离</param>
/// <param name="y">Y轴距离</param>
/// <param name="rotation">旋转度数</param>
/// <param name="align">对其方式</param>
/// <returns></returns>
public static Image GetImages(byte[] btImg, string strAlt, int width, int hegiht, float x, float y, float rotation, Alignment align)
{
Image img = Image.GetInstance(btImg);
SetImage(strAlt, width, hegiht, x, y, rotation, (int)align, ref img);
return img;
}


/// <summary>
/// 建立一个块
/// </summary>
/// <param name="strContent">输入内容</param>
/// <param name="font">字体</param>
/// <param name="bgColor">背景颜色</param>
/// <returns></returns>
public static Chunks GetChunks(string strContent, Fonts font, ColorList bgColor)
{
if (font == null)
{
font = new Fonts();
}
Chunks ck = new Chunks(strContent, font);
ck.SetBackground(bgColor);
return ck;
}

/// <summary>
/// 建立短语
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="font">字体</param>
/// <returns></returns>
public static Phrases GetPhrases(string strContent, Fonts font)
{
if (font == null)
{
font = new Fonts();
}
Phrases ph = new Phrases(strContent, font);
return ph;
}

/// <summary>
/// 建立一个段落
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="font">字体</param>
/// <param name="align">对其方式</param>
/// <returns></returns>
public static Paragraphs GetParagraphs(string strContent, Fonts font, Alignment align)
{
if (font == null)
{
font = new Fonts();
}
Paragraphs pg = new Paragraphs(strContent, font);
pg.Alignment = (int)align;
return pg;
}

/// <summary>
/// 建立一个章节
/// </summary>
/// <param name="title">章节名称</param>
/// <param name="number">编号</param>
/// <param name="content">章节内容</param>
/// <returns></returns>
public static Chapters GetChapter(Paragraphs title, int number, params Paragraphs[] content)
{
Chapters cp = new Chapters(title, number);
cp.AddAll(content);
return cp;
}

/// <summary>
/// 建立一个节点
/// </summary>
/// <param name="title">节点名称</param>
/// <param name="number">编号</param>
/// <param name="content">节点内容</param>
/// <returns></returns>
public static Sections GetSection(Paragraphs title, int number, params Paragraphs[] content)
{
Sections section = new Sections(title, number);
section.AddAll(content);
return section;
}
...全文
494 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
神一样的对友 2011-08-16
  • 打赏
  • 举报
回复
楼主,现在还有效没。。发给我一份,
byp2002@163.com
谢谢了
hackztx 2008-06-12
  • 打赏
  • 举报
回复
http://download.csdn.net/user/hackztx/

刚刚上传


要下载的朋友请稍等下!
zhengshaodong 2008-06-12
  • 打赏
  • 举报
回复
感想楼主 麻烦发我一份
yilanwuyu123 2008-06-12
  • 打赏
  • 举报
回复
mark 收藏
liulcster 2008-06-12
  • 打赏
  • 举报
回复
我也要一份
liulcster@gmail.com
谢谢!
hackztx 2008-06-12
  • 打赏
  • 举报
回复
已经发送了!
害怕飞的鸟 2008-06-12
  • 打赏
  • 举报
回复
俺也参考一下,可能什么时候需要做这方面的开发
cmnh4@126.com
Guid_Guid 2008-06-12
  • 打赏
  • 举报
回复
给me也一个吧
chenailuoding8@163.com

up
csr_hema 2008-06-12
  • 打赏
  • 举报
回复
不好意思,刚没看清楚,现在明白了,谢谢了啊
csr_hema 2008-06-12
  • 打赏
  • 举报
回复
收到了,谢谢,
在文件Function.cs中
BaseFont baseFT = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);

抛出异常"Font 'STSong-Light' with 'UniGB-UCS2-H' is not recognized."


是这种编码格式未识别吗?
wudi626 2008-06-12
  • 打赏
  • 举报
回复
学习!楼主,强啊!
bengold1979 2008-06-12
  • 打赏
  • 举报
回复
标记学习
hackztx 2008-06-12
  • 打赏
  • 举报
回复
发了!!

请问收到了吗??


/// <summary>
/// 创建中文字库对象(实现中文)
/// </summary>
/// <param name="fontname">传入字库(99999999为中文字库)请参考FontList对象</param>
/// <param name="fontsize">字体大小</param>
/// <param name="fontstyle">字体样式</param>
/// <param name="textcolor">文字颜色</param>
/// 如果传入为null或者为空那么设置为中文字库</param>
/// <returns></returns>
public static Fonts GetFonts(int fontindex, float fontsize, FontStyle fontstyle, ColorList textcolor)
{
Fonts font;
if (fontindex == 99999999)
{
BaseFont.AddToResourceSearch(@"E:\临时存储文件夹\CSHARP操作PDF文件\iTextAsian-1.0.dll");
BaseFont.AddToResourceSearch(@"E:\临时存储文件夹\CSHARP操作PDF文件\iTextAsianCmaps-1.0.dll");
BaseFont baseFT = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
font = new Fonts(baseFT, fontsize, (int)fontstyle, textcolor);
}
else
{
font = new Fonts(fontindex, fontsize, (int)fontstyle, textcolor);
}
return font;
}
注意这个方法,我一共给你发送了3个dll,其中两个是字库打包,支持中文,你要修改下dll的连接地址,否则会出现错误!
csr_hema 2008-06-12
  • 打赏
  • 举报
回复
shock2010@163.com

谢谢,现在不是很忙.想试试这方面的东西,呵呵
hackztx 2008-06-12
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 csr_hema 的回复:]
itextsharp的dll 这个DLL哪里有啊?
[/Quote]

你要做pdf这一方面吗?

如果需要的话我可以把dll发给你!

mail呢?
csr_hema 2008-06-12
  • 打赏
  • 举报
回复
itextsharp的dll 这个DLL哪里有啊?
hackztx 2008-06-12
  • 打赏
  • 举报
回复
当然通不过,首先你得有一个itextsharp的dll啊!!

using System;
using iTextSharp;//注意..
using iTextSharp.text;//注意..
using iTextSharp.text.pdf;//注意..
using System.IO;
using System.Collections.Generic;
using System.Data;
csr_hema 2008-06-12
  • 打赏
  • 举报
回复
是不是掉东西了,编译通不过啊
wuyi8808 2008-06-12
  • 打赏
  • 举报
回复
mark
GT7466 2008-06-12
  • 打赏
  • 举报
回复
加载更多回复(2)

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧