We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating a Pdf document with submit Button and Security Privileges

Is there any update on this?

As a seperate query on top of this. Can you give me example code when creating a new PDF from scratch if i want to add a submit button to the end of the pdf but also want to set the security privelidges on the pdf so that someone can save the pdf with data in form fields and then click the submit button.

I have already tried to get this working but have had no luck as i hit an error inside the form editors save method (in the code which is not accessible). Are these steps correct?

1) Create new Aspose.PDF pdf
2) Set the Security Privelidges on the SecurityPrivelidges object
2) Save to Memory Stream
3) Load memory stream into Form Editor Object
4) Use the AddSubmit Button function to add the submit button
5) Save the FormEditor to a memory stream,

I can get the add submit button to work if i dont set the security privelidges however i cannot save the document to the disk. I can also get the security privelidges to work if i dont add the submit button to the form. However when i try and add both on the save form there is an internal error thrown inside the save method.

Any help would be appreciated.

Hi Graeme,

Thanks for your query. Could you please share your sample code here? So we will test it at our side and will provide you information accordingly.

Sorry for the inconvenience faced.

Best Regards,
public MemoryStream CreateOfflinePDF(ApplicationForm applicationForm, ApplicationFormDocumentType docType)
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section PasswordSection = pdf.Sections.Add();
PasswordSection.TextInfo.FontName = "Helvetica";
SetPageHeader(PasswordSection, "Form Submission");
Text passwordText = new Text("

To submit the information in this form please supply your Bupa Survey system credentials and click the Save Button.

The details in your online form will be updated.

passwordText.TextInfo.FontName = "Helvetica";
passwordText.IsHtmlTagSupported = true;

Aspose.Pdf.Generator.Table tab1 = new Aspose.Pdf.Generator.Table();
TextInfo info = new TextInfo();
info.FontName = "Helvetica";
tab1.DefaultCellTextInfo = info;
MarginInfo margin = new MarginInfo();
margin.Bottom = 2;
margin.Top = 2;
margin.Inner = 0;
tab1.DefaultCellPadding = margin;
CreateUserNameAndPassword(tab1, PasswordSection);

Security security = new Security();
security.IsAnnotationsModifyingAllowed = true;
security.IsContentsModifyingAllowed = true;
security.IsCopyingAllowed = true;
security.IsScreenReadersAllowed = true;
security.IsPrintingAllowed = true;
security.IsFormFillingAllowed = true;
pdf.Security = security;
MemoryStream stream = new MemoryStream();

FormEditor fe = new FormEditor(stream, stream);
fe.AddSubmitBtn("Submit", pdf.PageCount , "Save", string.Format(@"{0}/en/Submit/Render/SaveOfflineDocument?applicationformid={1}",Settings.General.PortalURL, applicationForm.ID.ToString()), 500, 400, 550, 425);

return stream;

private void SetPageHeader(Section sec, string name)

Aspose.Pdf.Generator.Text t1 = new Aspose.Pdf.Generator.Text(sec);
// add the text object to Paragraphs collection of section

Aspose.Pdf.Generator.Segment seg1 = new Aspose.Pdf.Generator.Segment(t1);
// add the contents for Segment1
seg1.Content = string.Format("{0}", name);
// Specify the Font fore color for segement1

seg1.TextInfo.Color = new Aspose.Pdf.Generator.Color("White");
// specify the font size information for segment1
seg1.TextInfo.FontSize = 20;
// Specify the value for Opacity of text. Default is 1.0. Use it for multilayer effect
t1.Opacity = 1F;
// add the segment to segments collection of Text1
t1.ZIndex = 1;
//Tiff image cover the underlayer text
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec);

image1.ImageInfo.File = string.Format(@"{0}\Untitled.png", Settings.General.AppDataPath);
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Tiff;
image1.ZIndex = 0;
// Create a Floating Box object that will hold image file
Aspose.Pdf.Generator.FloatingBox box1 = new Aspose.Pdf.Generator.FloatingBox(60, 21);
// add Floating box to paragraphs collection of Section1

// Specify the left margin of FloatingBox1
box1.Left = -100;
// Specify the Top margin of FloatingBox1
box1.Top = -12;

box1.ZIndex = 0;
Text text = new Text("

text.IsHtmlTagSupported = true;


private static void CreateUserNameAndPassword(Table tab1, Section PasswordSection)
Aspose.Pdf.Generator.Row r1 = tab1.Rows.Add();
Aspose.Pdf.Generator.Row r2 = tab1.Rows.Add();
Aspose.Pdf.Generator.Cell c1 = r1.Cells.Add("User Name:");
c1.FitWidth = 100;

Aspose.Pdf.Generator.Cell c2 = r1.Cells.Add("");
c2.Padding.Left = 30;
c2.FitWidth = 150;
c2.Paragraphs[0].ID = "USERNAME";

Aspose.Pdf.Generator.Cell c3 = r2.Cells.Add("Password:");
c3.FitWidth = 100;

Aspose.Pdf.Generator.Cell c4 = r2.Cells.Add("");
c4.Padding.Left = 30;
c4.FitWidth = 150;
c4.Paragraphs[0].ID = "PASSWORD";


Aspose.Pdf.Generator.FormField textbox = new Aspose.Pdf.Generator.FormField();
textbox.FormFieldType = Aspose.Pdf.Generator.FormFieldType.Text;
textbox.FieldName = "PASSWORD";
textbox.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
textbox.ReferenceParagraphID = "PASSWORD";
textbox.TextIsPassword = true;
textbox.TextFontSize = 10;
textbox.FormWidth = 150;
textbox.FormHeight = 15;

Aspose.Pdf.Generator.FormField textbox2 = new Aspose.Pdf.Generator.FormField();
textbox2.FormFieldType = Aspose.Pdf.Generator.FormFieldType.Text;
textbox2.FieldName = "USERNAME";
textbox2.PositioningType = Aspose.Pdf.Generator.PositioningType.ParagraphRelative;
textbox2.ReferenceParagraphID = "USERNAME";
textbox2.TextFontSize = 10;
textbox2.FormWidth = 150;
textbox2.FormHeight = 15;

Hi Graeme,

Thanks for additional information, I’m working over your query and will update you soon.

Best Regards,

Hi Graeme,

Sorry for the inconvenience faced. I have managed to reproduce the issue at my end and logged it as PDFNEWNET-34843 in our bug tracking system for further investigation and resolution. You will be notified via this thread as soon as it gets resolved.

Thanks for your patience and cooperation.

Best Regards,

Hi Tilal,

Is there any work around or more correct way to allow the pdf to be edited and saved as well as having a submit button on it as i am sure other people must have this working with your product as its so fundamental.


Hi Graeme,

As a work around, can you please try Aspose.Pdf.Facades for setting security privileges after adding submit button? Please check following documentation for details/sample code.

Set privileges on an Existing Pdf File

Best Regards,

Hi Tilal,

I have now tried this and there is no error however the security settings have no effect on the generated document. I tried setting the privelidges so the document could be saved with form fields filled in. Think this could be another bug?


Hi Graeme,

Sorry for the delayed response. Can you please confirm are you getting this issue while saving to stream only or in case of disk also? As I’ve tried following code and can fill in the resulted form.

DocumentPrivilege privilege = DocumentPrivilege.AllowAll;
//open PDF document
PdfFileSecurity fileSecurity = new PdfFileSecurity();
//set document privileges

Best Regards,

Hi Tilal,

It is both saving to disk and stream. I can input text into the fields but cannot save the file from adobe.

Is there any update on this?


Hi Graeme,

Sorry for the inconvenience faced. I’m afraid, the reported issue is still not resolved due to some other priority tasks and it’s pending in the queue for analysis. I’ve requested the development team to share the ETA at their earliest and as soon as I get a feedback I’ll update you via this forum thread.

Thanks for your patience and understanding.

Best Regards