Skip to content

Instantly share code, notes, and snippets.

@luizpestana
Created December 8, 2016 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizpestana/628c8e6d4a2a83bb030481a8f0d9890f to your computer and use it in GitHub Desktop.
Save luizpestana/628c8e6d4a2a83bb030481a8f0d9890f to your computer and use it in GitHub Desktop.
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