2
A
回答
7
最后我解决了这个问题。 下面的代码将打开一个现有的PDF文件,并将按照我的预期将其所有字体更改为“盲文”。
private static void ChangeFont()
{
string strFile = @"E:\\xyz.pdf";
string OutputFile = @"E:\\xyz1.pdf";
PdfReader pdfReader = new PdfReader(strFile);
//Get first page,Generally we get font information on first page,however we can loop throw pages e.g for(int i=0;i<=pdfReader.NumberOfPages;i++)
PdfDictionary cpage = pdfReader.GetPageN(1);
if (cpage == null)
return;
PdfDictionary dictFonts = cpage.GetAsDict(PdfName.RESOURCES).GetAsDict(PdfName.FONT);
if (dictFonts != null)
{
foreach (var font in dictFonts)
{
var dictFontInfo = dictFonts.GetAsDict(font.Key);
if (dictFontInfo != null)
{
foreach (var f in dictFontInfo)
{
//Get the font name-optional code
var baseFont = dictFontInfo.Get(PdfName.BASEFONT);
string strFontName = System.Text.Encoding.ASCII.GetString(baseFont.GetBytes(), 0,
baseFont.Length);
//
//Remove the current font
dictFontInfo.Remove(PdfName.BASEFONT);
//Set new font eg. Braille, Areal etc
dictFontInfo.Put(PdfName.BASEFONT, new PdfString("Braille"));
break;
}
}
}
}
//Now create a new document with updated font
using (FileStream FS = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (Document Doc = new Document())
{
using (PdfCopy writer = new PdfCopy(Doc, FS))
{
Doc.Open();
for (int j = 1; j <= pdfReader.NumberOfPages; j++)
{
writer.AddPage(writer.GetImportedPage(pdfReader, j));
}
Doc.Close();
}
}
}
pdfReader.Close();
}
相关问题
- 1. 使用iTextSharp更改PDF作物/媒体框
- 2. 如何在PDF中使用字体的子集? (使用iTextSharp)
- 3. 使用iTextSharp和PDFStamper在PDF中使用不同的字体
- 4. 使用iTextSharp备份字体
- 5. 使用iTextSharp的PDF表格
- 6. 如何使用iTextSharp以pdf格式显示中文字体?
- 7. 如何使用iTextSharp设置PDF段落或字体行高?
- 8. 使用itextsharp从PDF获取字体大小
- 9. 使用itextsharp导出到pdf
- 10. 使用iTextSharp裁剪PDF
- 11. 使用iTextSharp生成PDF
- 12. 使用iTextsharp生成PDF
- 13. 是否可以更改Itextsharp List的字体?
- 14. 如何更改iTextSharp表的默认字体和颜色?
- 15. 在Itextsharp c中更改列表项的字体大小#
- 16. 使用ITextSharp和mvc损坏的pdf
- 17. 使用iTextSharp的转换HTML为PDF
- 18. 如何在itextSharp中设置HTML中的字体为PDF
- 19. 更改使用多个类的字体
- 20. 使用iTextSharp时分割的PDF大小更大
- 21. iTextSharp的PDF打印
- 22. iTextSharp的多页PDF
- 23. itextsharp postscript to PDF
- 24. Itextsharp下载PDF
- 25. 更改字体
- 26. 更改字体
- 27. 使用iTextSharp读取/修改PDF元数据
- 28. iTextSharp字体干扰普通字体
- 29. 使用itextSharp显示pdf中的特殊字符
- 30. 如何在印地语字体中创建iTextSharp pdf?
你的期望究竟是什么?只需更改所有文本元素的字体就足够了吗?你知道,如果以前使用的字体与新字体的度量标准不同,字体可能重叠或相距甚远,文本行可能超出正确的文档边界等,那么结果可能看起来非常难看。甚至这种丑陋的解决方案并不总是可能的,因为字符映射信息可能不包含在文档中的字体信息中,在自定义编码的情况下可能使得不可能知道哪个字符是哪个字符。 – mkl 2013-03-05 14:26:34