잠재적으로 사용할 수있는 것으로 책에 언급되어 있지만이 기능이 API에 있는지 여부는 FAQ에서 확인할 수 없습니다. 누구든지이 기능을 구현 한 경험이 있습니까?iTextSharp는 PDF 문서를 PDF/A로 변환 할 수 있습니까?
4
A
답변
7
This thread (2007 년 6 월) Paulo Soares는 PDF/A에 대한 지원을 표시하는 코드를 제공합니다. 여기에 C# 코드는 (그는 또한 자바 샘플을 가지고)입니다 :
는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 : 돋움 ")
희망이 당신은 여기 [http://www.color.org/srgbprofiles.xalter](http://www 프로파일을 다운로드 할 수 있습니다
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**
.. 누군가 도움이됩니다. color.org/srgbprofiles.xalter) –