DeleteOldLayer not always working

Technical support for Spire.PDF

Moderator: iceblue support

DeleteOldLayer not always working

Postby RNR GFX » Wed Jan 11, 2017 10:08 am

Hi,

I am trying to set up a workflow where multiple pdf's are generated with different layers deleted.
I created the source pdf's within Adobe Illustrator, but got mixed results when trying to delete layers.

After testing differen acrobat versions and settings for export, I finally realized that when hitting a regular "Save" in illustrator, a lot of extra data are generated i the pdf - namely some sort of layer history, which inserts multiple version of same naed layers in the pdf.

When using "Save as" and overwriting pdf at every save, DeleteOldLayer works perfectly, which is fine for current workflow, but a regular saved pdf with multiple same named layers will also have to work for later use.

Can you confirm my findings?
RNR GFX
 
Posts: 3
Joined: Thu Jan 05, 2017 12:14 pm

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Thu Jan 12, 2017 2:33 am

Dear RNR GFX,

Thanks for inquiry.
Please try to use following method.
Code: Select all
page.PageLayers.DeleteOldLayer("red line",true,true);

If the issue still exists, provide us more information, sample file and the code you were using to help us do an investigation.

Thanks,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby RNR GFX » Thu Jan 12, 2017 9:44 am

Hi Betsy,

Issue still remains with both
Code: Select all
page.PageLayers.DeleteOldLayer("remove",true,true);

and
Code: Select all
 
page.PageLayers.DeleteOldLayer("remove");


Attached is two files - a "normally" saved pdf (using Save command within illustrator - (test-regular-save-not-working.pdf)) , and a "Save as" version (test-save-as-working.pdf).


A new issue is occurring when testing.
The "Save as" pdf only has one layer, which results in this error:

Code: Select all
An error occured

Index was out of range. Must be non-negative and less than the size of the collection.
 Parameter name: index

EXCEPTION DETAILS

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
 Parameter name: index

at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)
   at Spire.Pdf.PdfPageLayerCollection.get_Item(Int32 index)
   at Spire.Pdf.PdfPageBase.get_DefaultLayer()
   at Spire.Pdf.PdfPageBase.get_Canvas()
   at BB3.CreatePlanImagesCBY.CustomSavingEventHandlerSpire(IContentService sender, SaveEventArgs`1 e) in C:\IIS\CreatePlanImagesCBY.cs:line 103



My code is:
Code: Select all
PdfDocument plan = new PdfDocument();
plan.LoadFromFile(serverPath + planUrl);
PdfPageBase basePage = plan.Pages[0];
basePage.PageLayers.DeleteOldLayer("remove"); // this is line 103


Seems it can't get Pages[0] ?
When adding another layer to the PDF and using "Save as", DeleteOldLayer works fine.
You do not have the required permissions to view the files attached to this post.
RNR GFX
 
Posts: 3
Joined: Thu Jan 05, 2017 12:14 pm

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Fri Jan 13, 2017 4:54 am

Dear RNR GFX,

Thanks for your detailed information.
I have noticed that the layer(named "remove" in file test-regular-save-not-working.pdf ) can not be deleted. I have posted the issue to our Dev team, we will inform you once there is any progress.
But about another file(test-save-as-working.pdf), you said it only has one layer, but I see it has two layers, see attachment.
And I can remove the layer named "remove" successfully and doesn't encounter any issue with the latest Spire.PDF Pack(Hot Fix) Version:3.8.121.
Maybe the sample file you provided is wrong ? Or you can try that version ?

Sincerely,
Betsy
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Mon Feb 06, 2017 8:45 am

Dear RNR GFX,

Thanks for waiting.
Now the first issue that the layer named "remove" in file test-regular-save-not-working.pdf can not be deleted has been resolved in Spire.PDF Pack(Hot Fix) Version:3.8.173. Welcome to test it.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Mon Feb 13, 2017 6:44 am

Dear RNR GFX,

Did you test the hotfix ? Has the issue been resolved ?
Looking forward to your reply.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby matthewcogniva » Wed May 31, 2017 6:38 pm

I am also have problems with PageLayers.

I am trying to use layers to put watermarks on documents. I add three layers to each page: header, body, and footer, each with a key. E.g.,
Code: Select all
PdfPageLayer layer = page.PageLayers.Add("header");

When I want to change a watermark I first try to remove any old layers. E.g.,
Code: Select all
page.PageLayers.DeleteOldLayer("header");

But, this doesn't seem to be working correctly.
Immediately after adding a layer to a page, I can see that it has been added to the PageLayers collection, and that it's Name property corresponds to the name I gave the layer. However, when I reopen the Pdf none of the layers have the name that was assigned. However, the layer seems to exist because the watermark was added successfully.

When DeleteOldLayer is called the it seems to either only remove the content of the specified layer, hide the layer, or it deletes the layer, but add another one that is not displayed. Either way, the old watermark is gone, but the number of layers has not gone down. The result is that the Pdfs grow in size with each successive layer added.

Additionally, sometimes when I open the Pdf in Adobe Acrobat Reader I get and error message "An error exists on this page..."
matthewcogniva
 
Posts: 3
Joined: Fri May 19, 2017 1:07 pm

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Thu Jun 01, 2017 8:44 am

Dear matthewcogniva,

Thanks for your inquiry.
I have noticed the DeleteOldLayer issue after adding layer, and posted it to our Dev team. We will inform you when there is any progress.
For the second issue getting and error message "An error exists on this page...", could you please provide us with input file and the entire code you were using here or send them to us(Support@e-iceblue.com) via email ? That would be very helpful to investigate the issue.

Thanks,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby matthewcogniva » Thu Jun 01, 2017 1:50 pm

I have also tried using RemoveAt() to remove a layer. This doesn't work either. It seems to me that you need to fix layer removal.

What I would like to see is:
* Removal of PageLayers fixed
* The persistence of the Name and LayerId properties on PageLayers
* Make the Name and LayerId properties public

This way I could iterate through the layers, find the one with the Name I'me looking for, and then use the Remove method that takes a PageLayer as a parameter to remove the layer.
matthewcogniva
 
Posts: 3
Joined: Fri May 19, 2017 1:07 pm

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Fri Jun 02, 2017 6:28 am

Dear matthewcogniva,

Thanks for response.
The only solution for deleting layer issue is waiting for the fix, and I have submitted your requirements(Make the Name and LayerId properties public) to our Dev team. And I will inform you when it is finished.
Sorry for inconvenience caused.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Tue Jun 27, 2017 6:25 am

Dear matthewcogniva,

Thanks for your waiting.
Now the deleting layer issue has been fixed in Spire.PDF Pack(Hot Fix) Version:3.9.181. Please note that the method page.PageLayers.Remove is to delete the layer just generated by code, and the method page.PageLayers.DeleteOldLayer is to delete the layer which already exists in input document.
In addition, sorry that we don't publish the Name and LayerId properties at present as some issues. We will publish them later, and let you know when the hotfix includes the properties.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby matthewcogniva » Thu Jul 06, 2017 3:11 pm

Hi Betsy,

Unfortunately, being able to find page layers by Name or LayerId is essential to my project. Without persistent identifiers I don't know which layers are my watermarks, and so I don't know which layers to remove when I want to change a watermark.

Matthew
matthewcogniva
 
Posts: 3
Joined: Fri May 19, 2017 1:07 pm

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Fri Jul 07, 2017 1:59 am

Dear Matthew,

Thanks for your feedback.
Our Dev team are adjusting the properties, and we will let you know when they are published. So sorry for the inconvenivence.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am

Re: DeleteOldLayer not always working

Postby Betsy.jiang » Mon Sep 25, 2017 9:52 am

Dear Matthew,

Thanks for your waiting.
Now we public the name of the layer, please download Spire.PDF Pack(Hot Fix) Version:3.9.360. And here is sample code for your reference.
Code: Select all
string name = doc.Layers[0].Name;

In addition, we adjust the code about layers.
Code: Select all
//add layer
PdfLayer layer = doc.Layers.AddLayer("red line", PdfVisibility.On);
PdfCanvas pcA = layer.CreateGraphics(doc.Pages[0].Canvas);
pcA.DrawLine(new PdfPen(PdfBrushes.Red, 1), new PointF(0, 100), new PointF(100, 100));
layer = doc.Layers.AddLayer("blue line");
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
pcB.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 150), new PointF(100, 150));
//remove the layer by name
doc.Layers.RemoveLayer(("red line");

If there is any question, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1527
Joined: Tue Sep 06, 2016 8:30 am


Return to Spire.PDF

Who is online

Users browsing this forum: No registered users and 0 guests