我无法在常见问题解答中找到此功能是否存在于API中,尽管它在本书中提到的可能可用。有没有人有任何实现此功能的经验?Can iTextSharp将PDF文档转换为PDF/A
4
A
回答
7
对This thread(2007年6月)Paulo Soares提供的代码显示了对PDF/A的支持。下面是C#代码(他也有一个Java样品):
private void PdfATest() {
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\\hello_A1-b_cs.pdf", FileMode.Create));
writer.PDFXConformance = PdfWriter.PDFA1B;
doc.Open();
PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
outi.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
outi.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
outi.Put(PdfName.S, PdfName.GTS_PDFA1);
// get this file here: http://old.nabble.com/attachment/10971467/0/srgb.profile
ICC_Profile icc = ICC_Profile.GetInstance("c:\\srgb.profile");
PdfICCBased ib = new PdfICCBased(icc);
ib.Remove(PdfName.ALTERNATE);
outi.Put(PdfName.DESTOUTPUTPROFILE, writer.AddToBody(ib).IndirectReference);
writer.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outi));
BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\arial.ttf", BaseFont.WINANSI, true);
Font f = new iTextSharp.text.Font(bf, 12);
doc.Add(new Paragraph("hello", f));
writer.CreateXmpMetadata();
doc.Close();
}
上面的链接包括下载的文件的ICC_Profile。
4
这是我的解析HTML文件并从中创建PDF/A存档文档的方法,也是使用样式表嵌入字体(为了避免错误:“所有字体都必须嵌入。 “T:黑体“)
希望这可以帮助别人..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.html.simpleparser;
namespace SaveAsPDF
{
class HtmlPdfConverter
{
public void RendererWebForm2PDFArchive(string fileName)
{
Console.WriteLine("Parsing HTML " + fileName);
Document document = new Document(PageSize.A4);
try
{
// we create a writer that listens to the document and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName + ".pdf", FileMode.Create));
//set document as arhive
writer.PDFXConformance = PdfWriter.PDFA1A;
document.Open();
//apply stylesheet to change font (and embedd it)
StyleSheet styles = new StyleSheet();
FontFactory.Register("c:\\windows\\fonts\\verdana.ttf");
styles.LoadTagStyle("body", "face", "Verdana");
//prepare html
StreamReader sr = new StreamReader(fileName, Encoding.Default);
string html = sr.ReadToEnd();
html = RemoveTag(html, "<title>", "</title>");
//convert string to stream
byte[] byteArray = Encoding.UTF8.GetBytes(html);
MemoryStream ms = new MemoryStream(byteArray);
//parse html
HTMLWorker htmlWorker = new HTMLWorker(document);
System.Collections.Generic.List<IElement> elements;
elements = HTMLWorker.ParseToList(new StreamReader(ms), styles);
foreach (IElement item in elements)
{
document.Add(item);
}
writer.CreateXmpMetadata();
document.Close();
Console.WriteLine("Done");
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.StackTrace);
}
}**strong text**
相关问题
- 1. iTextSharp将System.Web.UI.DataVisualization.Charting转换为pdf
- 2. 将文档转换为pdf
- 3. 使用iTextSharp将PDF文档转换为TIFF
- 4. 将文档转换为PDF格式
- 5. 将pdf文件转换为word文档
- 6. 使用iTextSharp将Gridview Templatefield转换为PDF
- 7. ITextSharp问题 - 将XML转换为PDF
- 8. 使用iTextSharp将PDF转换为PDFA1-A
- 9. 使用itextsharp将HTML转换为PDF
- 10. 使用documents4j将文档转换为PDf
- 11. C#。文档转换为PDF
- 12. 将PDF转换为Google文档
- 13. 如何将HTML转换为PDF文档
- 14. 如何将文档转换为PDF
- 15. 将word文档转换为pdf的vbscript
- 16. 将Word文档转换为PDF - Python
- 17. 将word文档转换为pdf
- 18. 将大型HTML文档转换为PDF
- 19. OpenOffice SDK:将文档转换为PDF
- 20. 将文档转换为html和pdf
- 21. asp.net itextsharp将文件格式文件转换为PDF
- 22. 如何将PDF转换为iTextSharp中的文本文件
- 23. 我可以使用itextsharp将图像转换为PDF/A文档吗?
- 24. iTextsharp将语言添加到PDF文档
- 25. 将页码添加到pdf文档(itextsharp)
- 26. iTextSharp的PDF文档属性
- 27. ITextSharp签署PDF/A文档
- 28. IIS可转换权限将文档转换为pdf?
- 29. 使用iTextSharp的转换HTML为PDF
- 30. iTextSharp - 如何将文档转换为字节[]
你可以在这里[http://www.color.org/srgbprofiles.xalter](http://www下载配置文件。 color.org/srgbprofiles.xalter) – 2012-07-30 17:37:11