Reputation: 21
I developed a console based application which browses the same folder all midnights to converts PDF in PDF/A using ghostscript.
It actually works but now we get hundreds of files and I will need to check if each file is a PDF or a PDF/A to avoid launching the script in PDF/A files.
Is there any solution to make the difference between PDF and PDF/A ?
Thank you in advance.
Upvotes: 0
Views: 2183
Reputation: 21
Sorry for the delay, I was sick.
I found the solution for my problem using Pac0's solution.
Instead of using XML, I used iTextSharp.xmp like that :
public static bool CheckIfPdfa(PdfReader reader)
{
if (reader.Metadata != null && reader.Metadata.Length > 0)
{
IXmpMeta xmpMeta = XmpMetaParser.Parse(reader.Metadata, null);
IXmpProperty pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance");
IXmpProperty pdfaidPart = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part");
reader.Close();
if (pdfaidConformance == null || pdfaidPart == null)
{
return false;
}
else
{
return true;
}
}
return false;
}
Thank you all for your answers.
Upvotes: 0
Reputation: 208
You can check whether a document claims to be compliant by examining the XMP Metadata of the document.
Using the Datalogics PDFL Library C# Interface:
using (var docInput = new Document("input.pdf"))
{
bool bIsPdfA1a = docInput.XMPMetadata.Contains("pdfaid:conformance=\"A\"");
}
Disclaimer: I work for Datalogics
Upvotes: 0
Reputation: 1003
You can use Spire.PDF to detect the conformance level of a PDF document. Check out the following code:
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("MS_Example.pdf");
PdfConformanceLevel conformance = pdf.Conformance;
Console.WriteLine(conformance.ToString());
Output:
Disclaimer:I'm an employee of Spire.
Upvotes: 0
Reputation: 23174
You can use a library like ITextSharp that will allow you to read PDF file.
To check if it is a PDF/A (well, actually to check if it claims to be a PDF/A, which should be sufficient for your needs) is a simple operation on reading PDF tags.
The code in this answer to another question should be what you need. It is VB.NET and it should be easy to translate to C# .
Basically :
pdfaid:conformance
, and see if its value is A
Upvotes: 1