Created
December 8, 2016 10:59
-
-
Save luizpestana/628c8e6d4a2a83bb030481a8f0d9890f to your computer and use it in GitHub Desktop.
Read PDF files from collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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