Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Read PDF files from collection
// Using Lib 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.