我無法在常見問題解答中找到此功能是否存在於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文件轉換爲word文檔
- 5. 使用iTextSharp將PDF轉換爲PDFA1-A
- 6. ITextSharp問題 - 將XML轉換爲PDF
- 7. 如何將文檔轉換爲PDF
- 8. 將大型HTML文檔轉換爲PDF
- 9. 將word文檔轉換爲pdf的vbscript
- 10. 將Word文檔轉換爲PDF - Python
- 11. OpenOffice SDK:將文檔轉換爲PDF
- 12. 將word文檔轉換爲pdf
- 13. 將PDF轉換爲Google文檔
- 14. C#。文檔轉換爲PDF
- 15. asp.net itextsharp將文件格式文件轉換爲PDF
- 16. iTextsharp將語言添加到PDF文檔
- 17. iTextSharp的PDF文檔屬性
- 18. 使用iTextSharp的轉換HTML爲PDF
- 19. iTextSharp - 如何將文檔轉換爲字節[]
- 20. 使用LEADTOOLS和PDF-TOOLS將pdf文檔轉換爲jpeg
- 21. 將PDF文件循環並將其轉換爲文檔
- 22. 將PDF轉換成Word文檔
- 23. 將文本轉換爲PDF
- 24. 將html文件轉換爲PDF使用Cocoa-Touch的iOS文檔
- 25. 文檔轉換爲PDF在C#
- 26. MS-Office文檔轉換爲.PDF格式
- 27. 使用spire文檔將原始文檔尺寸轉換爲pdf文檔
- 28. XFA格式轉換爲PDFA-1B
- 29. 使用iTextSharp將HTML樣式(虛線下劃線)轉換爲PDF
- 30. 將iframe文檔轉換爲父文檔
你可以在這裏[http://www.color.org/srgbprofiles.xalter](http://www下載配置文件。 color.org/srgbprofiles.xalter) – 2012-07-30 17:37:11