Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Nov 17, 2017 6:30 pm

I am evaluating your software for use in a .Net application. I need the ability to take a large PDF and split each page out as a PDF, PNG, and JPG.

On the surface your product meets my needs unless I'm working with a PDF that has hidden layers. The PNG and JPG file outputs are exporting correctly (layers remain hidden) but the exported PDF is showing all the layers.

During the split out of the page to it's individual PDF, is there a way to loop through the layers in the original page, determine if the layer visibility is on/of, and remove those that are off in the exported PDF being created?

Thank you!

DorisM7
 
Posts: 4
Joined: Fri Nov 17, 2017 5:00 pm

Mon Nov 20, 2017 3:57 am

Hello,

Thanks for your inquiry.
I have reproduced the issue and referred it to our dev team for a further investigation. For your suggestion of looping through the layers and remove the hidden ones, there's remains some error using this approach, and we will look into it.
Once there's any update, I will let you know.
Sorry for the inconvenience caused.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Nov 20, 2017 7:23 am

Hello DorisM7,

After a further investigation, we came up with a temporary workaround for you. Please refer to the following code.
Code: Select all
 List<string> lists = new List<string>();
            using (PdfDocument doc = new PdfDocument(@"HideLayersSample.pdf"))
            {
                foreach (PdfLayer ly in doc.Layers)
                {
                    if (ly.Visibility == PdfVisibility.Off)
                    {
                        lists.Add(ly.Name);
                    }
                }
                for (int i = 0; i < lists.Count;i++ )
                {
                    doc.Layers.RemoveLayer(lists[i]);

                }
                String pattern = "SplitDocument-{0}.pdf";
                doc.Split(pattern);
                String lastPageFileName
                    = String.Format(pattern, doc.Pages.Count - 1);
                doc.Close();


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Sun Nov 26, 2017 6:09 pm

The code suggestion you provided does not work. The PDFDocument does not have a "Layers" property.

DorisM7
 
Posts: 4
Joined: Fri Nov 17, 2017 5:00 pm

Mon Nov 27, 2017 1:18 am

Hi DorisM7,

Thanks for your feedback.
Please use the latest hotfix Spire.PDF Pack(Hot Fix) Version:3.9.462.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

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

DorisM7
 
Posts: 4
Joined: Fri Nov 17, 2017 5:00 pm

Tue Nov 28, 2017 2:13 am

Hello,

Thanks for your feedback.
I have reproduced the issue and logged it in our bug tracking system. Once there's any update, I will inform you.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Dec 05, 2017 6:34 am

Hello,

After a further investigation, our dev team found there are indeed 8 layers in your document. Among them, 2 are visible, 1 is hidden and 5 are invisible. According to the official standard, the invisible layers will not display in the document, this is why you can only see 3 layers when opening the document in pdf readers like Adobe. Here is the screen shoot for the existing of 8 layers when opening with a special pdf editing tool.
layers.png

As for the issue that the generated pdf can't be opened, it has been resolved in the Spire.PDF 3.9.503, please download and have a check.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Dec 05, 2017 3:01 pm

Thank you for the explanation.

When testing against a multi-page file, I am still having an issue with the split out files not being able to be opened after layers are removed. At this point, I am going to move on to looking for another solution.

DorisM7
 
Posts: 4
Joined: Fri Nov 17, 2017 5:00 pm

Wed Dec 06, 2017 1:25 am

Hello,

Thanks for your feedback.
Please feel free to contact us if you need further assistance.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF