I am using iTextSharp 5.5.10.0.
I have a PDF with several layers resulting from having joined several files. When I open it with Acrobat Reader, the layers and the original names of the files that I joined appear.
First problem:
If I use this code once, in the Acrobat panel, the layers disappear and the names of the files remain attached:
Public Shared Sub OcultarLayers(ByVal source As String, ByVal destination As String)
Using reader = New PdfReader(source)
reader.ConsolidateNamedDestinations()
reader.RemoveUnusedObjects()
Using stamper As PdfStamper = New PdfStamper(reader, New FileStream(destination, FileMode.Create, FileAccess.Write, FileShare.None))
Dim capas = From cada In stamper.GetPdfLayers
For Each capa In capas
capa.Value.OnPanel = False
Next
End Using
End Using
End Sub
I have to use it twice so that the names of the files do not appear:
Public Shared Sub OcultarLayers(ByVal source As String, ByVal destination As String)
Using memo As MemoryStream = New MemoryStream
Using readerMemo = New PdfReader(source)
readerMemo.ConsolidateNamedDestinations()
readerMemo.RemoveUnusedObjects()
Using stamperMemo As PdfStamper = New PdfStamper(readerMemo, memo)
stamperMemo.Writer.CloseStream = False
Dim capas = From cada In stamperMemo.GetPdfLayers
For Each capa In capas
capa.Value.OnPanel = False
Next
End Using
End Using
memo.Position = 0
Using reader = New PdfReader(memo)
reader.ConsolidateNamedDestinations()
reader.RemoveUnusedObjects()
Using stamper As PdfStamper = New PdfStamper(reader, New FileStream(destination, FileMode.Create, FileAccess.Write, FileShare.None))
Dim capas = From cada In stamper.GetPdfLayers
For Each capa In capas
capa.Value.OnPanel = False
Next
End Using
End Using
End Using
Second Problem:
It does not work to put capa.Value.OnPanel = True
again.