c# - Make a pdf conforming PDF/A with only images using iTextSharp -
i'm using itextsharp generate pdf-a documents images. far i've not been successful.
edit: i'm using itextsharp generate pdf
all try make pdf-a document (1a or 1b, whatever suits), images. code i've come far, keep getting errors when try validate them pdf-tools or validatepdfa.
this errors pdf-tools (using pdf/a-1b validation): edit: markinfo , color space arn't yet working. rest okay
validating file "0.pdf" conformance level pdfa-1a key markinfo required missing. device-specific color space (devicergb) without appropriate output intent used. document not conform requested standard. document contains device-specific color spaces. document doesn't provide appropriate logical structure information. done.
main flow
var output = new memorystream(); using (var iccprofilestream = new filestream("topdfconverter/colorprofiles/srgb_v4_icc_preference_displayclass.icc", filemode.open)) { var document = new document(new rectangle(pagesize.a4.width, pagesize.a4.height), 0f, 0f, 0f, 0f); var pdfwriter = pdfwriter.getinstance(document, output); pdfwriter.pdfxconformance = pdfwriter.pdfa1a; document.open(); var pdfdictionary = new pdfdictionary(pdfname.outputintent); pdfdictionary.put(pdfname.outputcondition, new pdfstring("srgb iec61966-2.1")); pdfdictionary.put(pdfname.info, new pdfstring("srgb iec61966-2.1")); pdfdictionary.put(pdfname.s, pdfname.gts_pdfa1); var iccprofile = icc_profile.getinstance(iccprofilestream); var pdficcbased = new pdficcbased(iccprofile); pdficcbased.remove(pdfname.alternate); pdfdictionary.put(pdfname.destoutputprofile, pdfwriter.addtobody(pdficcbased).indirectreference); pdfwriter.extracatalog.put(pdfname.outputintent, new pdfarray(pdfdictionary)); var image = prepareimage(imagebytes); document.open(); document.add(image); pdfwriter.createxmpmetadata(); pdfwriter.closestream = false; document.close(); } return output.getbuffer();
this prepareimage()
it's used flatten image bmp, don't need bother alpha channels.
private image prepareimage(stream stream) { bitmap bmp = new bitmap(system.drawing.image.fromstream(stream)); var file = new memorystream(); bmp.save(file, imageformat.bmp); var image = image.getinstance(file.getbuffer()); if (image.height > pagesize.a4.height || image.width > pagesize.a4.width) { image.scaletofit(pagesize.a4.width, pagesize.a4.height); } return image; }
can me direction fix errors? device-specific color spaces
edit: more explanation: i'm trying achieve is, converting scanned images pdf/a long-term data storage
edit: added files i'm using test with
pdfs , pictures.rar (3.9 mb)
https://mega.co.nz/#!n8pclygl!njojqso3euvrqlvyh3c43yw-u_u35nqeb0svc6giasq
ok, checked 1 of files in callas pdftoolbox , says: "device color space used no pdf/a output intent". took sign wrong while writing output intent document. converted document pdf/a-1b same tool , difference obvious.
perhaps there other errors need fix, first error here put key in catalog dict pdf file named "outputintent". that's wrong: page 75 of pdf specification states key should named "outputintents".
like said, perhaps there other problems file beyond this, wrong name key causes pdf/a validators not find output intent try put in file...
Comments
Post a Comment