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

Free Support Forum - aspose.com

Problem when we set license

Hi

We are using Aspose.Pdf.Kit to add a javascript to a pdf document to always show the current date when we open the pdf file. This works just fine as long as we don't set the aspose license. When we set the aspose license the text is all blurry and impossible to rea (see the attached file). We are using Aspose.Pdf.Kit v 4.0.0.0 and the code below:

Stream input = File.Open(@"c:\temp\input.pdf", FileMode.Open);

//Aspose.Pdf.Kit.License lic = new License();
//lic.SetLicense(File.Open(@"C:\temp\Aspose.Total.lic", FileMode.Open));

//Add javascript
MemoryStream tempStream = new MemoryStream();
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(input);
contentEditor.AddDocumentAdditionalAction(PdfContentEditor.DocumentOpen, "var d = new Date();var sDate = util.printd('yyyy-mm-dd', d);this.getField('datum').value = 'Only valid: ' + sDate;");
contentEditor.Save(tempStream);


//Add form fields
MemoryStream tempStream2 = new MemoryStream();
FormEditor editor = new FormEditor(tempStream, tempStream2);
editor.AddField(FieldType.Text, "datum", 1, 50, 0, 350, 50);
editor.Save();

//Set fields to read only.
//Note! File must be saved before fields are set as read only
MemoryStream finalStream = new MemoryStream();
FormEditor editor2 = new FormEditor(tempStream2, finalStream);
editor2.SetFieldAttribute("datum", PropertyFlag.ReadOnly);
editor2.Save();

//Save file
FileStream fs = File.Create(@"c:\temp\output.pdf");
finalStream.Position = 0;
byte[] buffer = new byte[finalStream.Length];
finalStream.Read(buffer, 0, Convert.ToInt32(finalStream.Length));
fs.Write(buffer, 0, buffer.Length);
fs.Close();

Any ideas on how to solve this?

Hi Ola,

I have reproduced this problem at my end and logged it as PDFKITNET-18523 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

Hi

Do you have any status on this issue? When can we expect a solution?

If it will take a while do you have any suggestions on a workaround that makes it possible to always print todays date when a pdf document is opened and printed?

Hi Ola,

I’m sorry to share with you that this issue is not yet resolved; however, I have asked our development team to share the ETA of this issue. You’ll be updated via this forum thread once we get a clear idea of the estimate. Moreover, I’m afraid, we’re unable to share the workaround for this issue at the moment either.

We’re sorry for the inconvenience.
Regards,

The issues you have found earlier (filed as 18523) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi

It is still not good enough. I have added a FormFieldFacade to format the text but this results in that the text is not displayed properly. Try the following code:

Stream input = File.Open(@"c:\temp\input.pdf", FileMode.Open);
//Aspose.Pdf.Kit.License lic = new License();
//lic.SetLicense(File.Open(@"C:\temp\Aspose.Total.lic", FileMode.Open));
//Add javascript
MemoryStream tempStream = new MemoryStream();
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(input);
contentEditor.AddDocumentAdditionalAction(PdfContentEditor.DocumentOpen, "var d = new Date();var sDate = util.printd('yyyy-mm-dd', d);this.getField('datum').value = 'SOPen endast giltig utskriftsdatum: ' + sDate;");
contentEditor.Save(tempStream);

//Add form fields
MemoryStream tempStream2 = new MemoryStream();
FormEditor editor = new FormEditor(tempStream, tempStream2);
FormFieldFacade facade = new FormFieldFacade();
editor.Facade = facade;
facade.Font = FontStyle.TimesRoman;
facade.FontSize = 10;
facade.TextColor = System.Drawing.Color.FromArgb(100, 100, 100);
editor.AddField(FieldType.Text, "datum", 1, 50, 0, 350, 50);
editor.ResetFacade();
editor.Save();

//Set fields to read only.
//Note! File must be saved before fields are set as read only
MemoryStream finalStream = new MemoryStream();
FormEditor editor2 = new FormEditor(tempStream2, finalStream);
editor2.SetFieldAttribute("datum", PropertyFlag.ReadOnly);
editor2.Save();
//Save file
FileStream fs = File.Create(@"c:\temp\output.pdf");
finalStream.Position = 0;
byte[] buffer = new byte[finalStream.Length];
finalStream.Read(buffer, 0, Convert.ToInt32(finalStream.Length));
fs.Write(buffer, 0, buffer.Length);
fs.Close();Stream input = File.Open(@"c:\temp\input.pdf", FileMode.Open);
//Aspose.Pdf.Kit.License lic = new License();
//lic.SetLicense(File.Open(@"C:\temp\Aspose.Total.lic", FileMode.Open));
//Add javascript
MemoryStream tempStream = new MemoryStream();
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(input);
contentEditor.AddDocumentAdditionalAction(PdfContentEditor.DocumentOpen, "var d = new Date();var sDate = util.printd('yyyy-mm-dd', d);this.getField('datum').value = 'SOPen endast giltig utskriftsdatum: ' + sDate;");
contentEditor.Save(tempStream);

//Add form fields
MemoryStream tempStream2 = new MemoryStream();
FormEditor editor = new FormEditor(tempStream, tempStream2);
FormFieldFacade facade = new FormFieldFacade();
editor.Facade = facade;
facade.Font = FontStyle.TimesRoman;
facade.FontSize = 10;
facade.TextColor = System.Drawing.Color.FromArgb(100, 100, 100);
editor.AddField(FieldType.Text, "datum", 1, 50, 0, 350, 50);
editor.ResetFacade();
editor.Save();

//Set fields to read only.
//Note! File must be saved before fields are set as read only
MemoryStream finalStream = new MemoryStream();
FormEditor editor2 = new FormEditor(tempStream2, finalStream);
editor2.SetFieldAttribute("datum", PropertyFlag.ReadOnly);
editor2.Save();
//Save file
FileStream fs = File.Create(@"c:\temp\output.pdf");
finalStream.Position = 0;
byte[] buffer = new byte[finalStream.Length];
finalStream.Read(buffer, 0, Convert.ToInt32(finalStream.Length));
fs.Write(buffer, 0, buffer.Length);
fs.Close();

The resulting text is found in the attached file.

Note that I have tried this with version 4.9.0.0 of Aspose.Pdf.Kit without a valid license. Our license only includes updates until july this year and I don't want to pay for a new license until we see that your product actually fits our needs.

Hi Ola,

I have tested this issue using the latest version 4.9.0 and I couldn’t notice this issue. Please see the attached output PDF file. Kindly make sure that you’re using the latest (4.9.0) version. Moreover, I would like to share with you that you can get a fully functioning temporary license from this link and try it at your end before upgrading your license.

Please try the latest version and share the results with us. We’re sorry for the inconvenience.
Regards,


Hi

It doesnt look like you have used the latest code that I submitted. I have added a FormFieldFacade that makes the text gray, 10 pt and Times New Roman. In your submitted output.pdf is the text black and Arial.

Hello Ola,

I have again tested the scenario over Windows7 Enterprise 64 Bit where my .NET Framework version is .NET Compact Framework 3.5 & .NET Compact Framework 2.0 SP2 and Aspose.Pdf.Kit for .NET version is 4.9.0 and I am unable to notice the problem.

I have used the same code snippet that you have shared over 262848. The resultant PDF that I have generated is in attachment. Please take a look.

In case the problem is still not resolved or you have any further query, please feel free to contact. We apologize for your inconvenience.