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. 使用iTextSharp更改PDF作物/媒体框
- 3. 如何使用iTextSharp更改我的PDF文档的字体大小
- 4. 使用iTextSharp修改PDF
- 5. 更改PDF中的字体
- 6. 如何在PDF中使用字体的子集? (使用iTextSharp)
- 7. 使用iTextSharp保存文件PDF文件中使用的字体
- 8. 使用iTextSharp和PDFStamper在PDF中使用不同的字体
- 9. 更改PDF字段的字体
- 10. 如何使用itextsharp更改PDF Formular的按钮图标?
- 11. 如何使用iTextsharp更改PDF中第二页的页边距?
- 12. 使用iTextSharp备份字体
- 13. 使用iTextSharp的PDF表格
- 14. 如何使用iTextSharp以pdf格式显示中文字体?
- 15. 使用itextsharp从PDF获取字体大小
- 16. 使用itextsharp从Pdf中提取字体颜色
- 17. 如何使用iTextSharp设置PDF段落或字体行高?
- 18. 使用iTextSharp签署pdf文件后更改签名外观
- 19. 使用iTextSharp更改PDF注释属性C#
- 20. 使用iTextSharp 4.1.6.0数字签名PDF 4.1.6.0
- 21. 使用itextsharp根据大小将pdf拆分为更小的pdf
- 22. iTextSharp修改pdf属性
- 23. 使用iTextSharp裁剪PDF
- 24. 使用iTextSharp生成PDF
- 25. 使用iTextsharp生成PDF
- 26. 使用itextsharp导出到pdf
- 27. 在Itextsharp c中更改列表项的字体大小#
- 28. 是否可以更改Itextsharp List的字体?
- 29. 如何更改iTextSharp表的默认字体和颜色?
- 30. iTextSharp的和pdf
你的期望究竟是什么?只需更改所有文本元素的字体就足够了吗?你知道,如果以前使用的字体与新字体的度量标准不同,字体可能重叠或相距甚远,文本行可能超出正确的文档边界等,那么结果可能看起来非常难看。甚至这种丑陋的解决方案并不总是可能的,因为字符映射信息可能不包含在文档中的字体信息中,在自定义编码的情况下可能使得不可能知道哪个字符是哪个字符。 – mkl 2013-03-05 14:26:34