Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Read PDF files from collection
// Using Lib iTextSharp: http://sourceforge.net/projects/itextsharp/
PdfReader reader = new PdfReader("Portifolio.pdf"); // Seu arquivo collection
for (int x = 0; x < reader.XrefSize; x++) // Loop em todos os objetos
{
PdfObject obj = reader.GetPdfObject(x);
if ((obj != null) && (obj.IsDictionary()) && (obj.ToString().EndsWith("/Filespec")))
{
PdfDictionary filespec = (PdfDictionary)obj;
PdfDictionary refs = filespec.GetAsDict(PdfName.EF);
foreach (KeyValuePairkey in refs)
{
// Salvando sub arquivos
FileStream fos = new FileStream(x + ".pdf", FileMode.CreateNew, FileAccess.Write);
PRStream stream = (PRStream)reader.GetPdfObject(refs.GetAsIndirectObject(key.Key).Number);
byte[] pdfb = PdfReader.GetStreamBytes(stream);
fos.Write(pdfb, 0, pdfb.Length);
fos.Flush();
fos.Close();
}
}
}
reader.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment