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.

Thu Nov 16, 2017 8:01 pm

I have tried your fieldwidget removeal code as per your example.
widgets.FieldsWidget.RemoveAt(i);

This code removed the signature, but did not remove all of the blocked permissions. We were unable to make annotations on the document.

I tried it on another locked document and there was no signature, so nothing happened.

I need to be able to remove these restrictions.
pdfrestrictions.PNG

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Nov 17, 2017 8:14 am

Hello,

Thanks for your feedback. I find your PDF document is double restricted. Hence, after remove the signature, you also need to remove the Password Security. Please download Spire.PDF Pack(Hot Fix) Version:3.9.462 and refer to the below code snippet to have a try.
Code: Select all
pdfDocument.Security.Encrypt("","",PdfPermissionsFlags.Default,PdfEncryptionKeySize.Key128Bit,"password");


Best reagrds,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Nov 17, 2017 3:52 pm

I tried the new hotfix, but it does not work because we do not have the password.

There are websites that will remove all security on a pdf like
https://smallpdf.com/unlock-pdf

How are they doing it without a password?

Capture.PNG

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Mon Nov 20, 2017 6:23 am

Hello,

Thanks for your feedback.
The documentation you shared is something like password cracking. I am sorry our Spire.Pdf doesn't support to do so. If you don't have the password of Password Security, Spire.Pdf can't remove it.

Best reagrds,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Nov 20, 2017 4:21 pm

Ok, then how can I open a pdf, and then PRINT that file to pdf?

I iknow how to open a pdf with spire.pdf, how do I PRINT to pdf?

Is this the best way?
Code: Select all
         var lockedFileName = "c:\\temp\\locked2.pdf";
         var unlockedFileName = "c:\\temp\\unlocked.pdf";
         PdfDocument pdf = new PdfDocument(lockedFileName);
         pdf.PrintSettings.PrinterName = "Microsoft Print to PDF";
         pdf.PrintSettings.PrintToFile(unlockedFileName);
         pdf.Print();


I am concerned that the azure webserver that my code will be running on will not have the "Microsoft Print to PDF" printer installed.

Can I do it without this printer?
pdf.PrintSettings.PrinterName = "Microsoft Print to PDF";

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Tue Nov 21, 2017 6:10 am

Hello,

Thanks for your reply. I think you want to remove the password in that way. But if there is no PDF printer, you can't do it by printing to PDF. With further investigation, I find another solution to achieve that, create a new PDF document and keep the contents from your locked PDF. Please refer to the below code snippet.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"locked.pdf");
            PdfDocument pdf1 = new PdfDocument();
            PdfPageBase page;
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                page = pdf1.Pages.Add(pdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
                pdf.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
            }
            pdf1.SaveToFile("unlocked.pdf");


Best reagrds,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Nov 24, 2017 9:08 am

Hello,

Greeting from E-iceblue.
Is the solution I provided helpful to you?
Your feedback will be greatly appreciated.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Mon Nov 27, 2017 7:15 pm

Simon, your second solution works GREAT!

It is faster than printing and it creates a file that is the same size.

Thank you for this solution.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Tue Nov 28, 2017 1:27 am

Hello,

Thanks for your feedback. If there is any other question, please feel free to contact us.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Thu Feb 01, 2018 5:21 pm

Simon, as I stated above, your unlock code works great, but we have now discovered that the code is removing the bookmarks.

Could you alter the code so that we add the existing bookmarks back into the document?

Thank you.

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Fri Feb 02, 2018 9:21 am

Hello,

Thanks for your inquiry. After investigation, I found a solution to accomplish your task. Please refer to the below code snippet.
Code: Select all
            PdfDocument pdf = new PdfDocument(@"Template.pdf");
             //get bookmarks from source file
            var bms= pdf.Bookmarks;

            PdfDocument doc = new PdfDocument();
            PdfPageBase page;
            for (int i = 0; i < pdf.Pages.Count; i++)
            {
                //copy content
                page = doc.Pages.Add(pdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
                pdf.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
            }

            //copy bookmarks
            for (int i = 0; i < bms.Count; i++)
            {
                //add vendor bookmark
                PdfDestination vendorBookmarkDest = new PdfDestination(bms[i].Destination.Page, bms[i].Destination.Location);
                PdfBookmark vendorBookmark = doc.Bookmarks.Add(bms[i].Title);
                vendorBookmark.Color = bms[i].Color;
                vendorBookmark.DisplayStyle = bms[i].DisplayStyle;
                vendorBookmark.Action = new PdfGoToAction(vendorBookmarkDest);
     
                for (int j = 0; j < bms[i].Count; j++)
                {               
                    //add part bookmark
                    PdfDestination partBookmarkDest = new PdfDestination(bms[i][j].Destination.Page, bms[i][j].Destination.Location);
                    PdfBookmark partBookmark = vendorBookmark.Add(bms[i][j].Title);
                    partBookmark.Color = bms[i][j].Color;
                    partBookmark.DisplayStyle = bms[i][j].DisplayStyle;
                    partBookmark.Action = new PdfGoToAction(partBookmarkDest);
                }
            }
            doc.SaveToFile("unlockedBookmark.pdf");


Best regards,
Simon
E-icelbue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Feb 02, 2018 8:08 pm

Simon that worked great.

Thank you for your help.

Terrence

terrence@mactexas.com
 
Posts: 95
Joined: Tue May 19, 2015 8:09 pm

Mon Feb 05, 2018 1:37 am

Hello Terrence,

Glad to hear that. If any other question, welcome to write to us.

Best regards,
Simon
E-icelbue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.PDF