Mon Nov 27, 2017 2:58 pm
Thank you for getting back to me. The code provided does work with the updated DLLs but it applies to the document as a whole which could be an issue if I have multiple pages with layers named the same.
I tested it with a single page PDF (attached) that has 3 layers (CUT, LOGO, BLEED) and the BLEED layer is set to invisible. If I set a breakpoint, the code detects 8 layers (Layer1, CUT, BLEED, LOGO, CUT, BLEED, LOGO, CUT). When I step through it, the hidden layer is correctly identified as not being visible and is removed. The document layers drop to 6 (as expected given the layers detected) but PDF generated for the page cannot be opened.
I'm looking for a solution that would loop through the pages of a large document, examine it's layers, remove (or keep hidden) any layers set to "off", save the individual page as a 3 files (PDF, PNG, and JPG).
Here is the code I have cobbled together based on my needs. Maybe I'm doing something in the wrong order??
Dim lists As New List(Of String)()
Using doc As New Spire.Pdf.PdfDocument(filepath)
For Each ly As Spire.Pdf.Graphics.Layer.PdfLayer In doc.Layers
MsgBox(ly.Name)
If ly.Visibility = Spire.Pdf.Graphics.Layer.PdfVisibility.Off Then
lists.Add(ly.Name)
End If
Next
For i As Integer = 0 To lists.Count - 1
doc.Layers.RemoveLayer(lists(i).ToString())
Next
For pageCount As Integer = 1 To doc.Pages.Count
Dim strPage As String = pageCount.ToString("000")
'save to images
Dim fileName As String = ImagePath & "-Spit_Layer_" & strPage
Using image As System.Drawing.Image = doc.SaveAsImage(pageCount)
image.Save(fileName & ".png", System.Drawing.Imaging.ImageFormat.Png)
image.Save(fileName & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
End Using
Next
Dim pattern As [String] = ImagePath & "-Spit-{0}.pdf"
doc.Split(pattern)
Dim lastPageFileName As [String] = [String].Format(pattern, doc.Pages.Count - 1)
doc.Close()
End Using
Login to view the files attached to this post.