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

Free Support Forum - aspose.com

Problem with Mender object

Hi,

We are trying to read a field's co-ordinates from PDF file & replace those co-ordinates with an Image & then remove that field.

I'm using following code:

_________________________________________________________________________

Dim objLic As New Aspose.Pdf.Kit.License
objLic.SetLicense("Aspose.Total.lic")
Dim myLib As New PDFSplit
Dim form As New Aspose.Pdf.Kit.Form(sFilename)
Dim sFields() As String = form.FieldNames

If Array.IndexOf(sFields, sFieldName) <> -1 Then
Dim box As Rectangle = form.GetFieldFacade(sFieldName).Box

Dim msOut As New MemoryStream()

Dim Mender As New PdfFileMend(myLib.CreateMemoryStream(sFilename), msOut)
Mender.AddImage(sImageFilename, 1, box.X, box.Y - box.Height, box.Right, box.Bottom)
Mender.Close()

Threading.Thread.Sleep(500)

Dim fsFinalOut As New FileStream(sFilename, FileMode.Create, FileAccess.Write)
Dim myformeditor As New Aspose.Pdf.Kit.FormEditor(msOut, fsFinalOut)
myformeditor.RemoveField(sFieldName)
myformeditor.Save()
fsFinalOut.Close()
End If
_________________________________________________________________________

Problem I'm facing is that whenever I supply the sFileName with local machine path, it works perfectly, but instead of that if I give any other machine's path to store the output file, it fails & gives no error!

I have checked for access permissions on other machine's shared folder & they are ok. (Other part of my application which are creating file/folder related activities(creation/deletion) are working fine)... so it doesn't seems like an access permission issue.
We have tried this code firstly with (filename,filename) version of PdfFileMend, but found that even after mender.close statement, file was not created completely. I was getting Object Reference not set error for

Dim myformeditor As New Aspose.Pdf.Kit.FormEditor(1stfile,2ndfile)

this statement. Investigating further, came to know that, mender is not flushing the file & releasing it immidiately after mender.close statement & file was remaining locked untill it finishes flushing. Due to this, to avoid any file handling during this process, we switched to (stream,stream) version, but still getting the same error! which was more confusing.

This problem was ocurring frequently whenever we tried to use other machine's shared path & sometimes on the local machine's path too.

Hi Manoj,

Thanks for using our products.

I have tested this scenario in details while using Aspose.Pdf for .NET 7.0.0 and I am unable to reproduce this problem when trying to save the document locally over my system. As per my observations, once the Mender.Close() is called, the source PDF file is released. After removing the Form field, I have also tried adding watermark stamp to the output generated with PdfFileMend and as per my observations, the watermark text is properly appearing on resultant PDF. Please take a look over the following updated code that I have used to test this scenario.

Also please note that you have been using legacy Aspose.Pdf.Kit for .NET and there has been several improvements/enhancements in product since we have released a merged release version of Aspose.Pdf for .NET. I would suggest you to please try using the latest release version of Aspose.Pdf for .NET 7.0.0 and in case you still face the same problem, please feel free to contact. We are sorry for your inconvenience.

I would also recommend you to please visit the following links for further details on


[VB.NET]

' Dim myLib As New PDFSplit

Dim form As New Aspose.Pdf.Facades.Form("D:\pdftest\2DA22000-stream.PDF")

Dim sFields() As String = form.FieldNames

If Array.IndexOf(sFields, "btnSubmit") <> -1 Then

Dim box As System.Drawing.Rectangle = form.GetFieldFacade("btnSubmit").Box

Dim msOut As New MemoryStream()

Dim Mender As New PdfFileMend("D:\pdftest\2DA22000-stream.PDF", "D:\pdftest\2DA22000-stream-OUTPUT.PDF")

Mender.AddImage("D:\\pdftest\\books.png", 1, box.X, box.Y - box.Height, box.Right, box.Bottom)

Mender.Close()

Dim fsFinalOut As New FileStream("D:\pdftest\2DA22000-stream-OUTPUT-RemovedField.PDF", FileMode.Create, FileAccess.Write)

Dim fsFinalIn As New FileStream("D:\pdftest\2DA22000-stream-OUTPUT.PDF", FileMode.Open)

Dim myformeditor As New Aspose.Pdf.Facades.FormEditor(fsFinalIn, fsFinalOut)

myformeditor.RemoveField("btnSubmit")

myformeditor.Save()

fsFinalOut.Close()

'close input PDF

fsFinalIn.Close()

'open document

Dim fileStamp As New PdfFileStamp("D:\pdftest\2DA22000-stream-OUTPUT.PDF", "D:\pdftest\2DA22000-stream-Stamped.pdf")

'create stamp

Dim stamp As New Aspose.Pdf.Facades.Stamp()

stamp.BindLogo(New FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, True, 14))

stamp.SetOrigin(200, 200)

stamp.Rotation = 90.0F

stamp.IsBackground = True

'add stamp to PDF file

fileStamp.AddStamp(stamp)

'save updated PDF file

fileStamp.Close()

End If

Hi,

Thanks for the reply.

I have tested this scenario in details while using Aspose.Pdf for .NET 7.0.0 and I am unable to reproduce this problem when trying to save the document locally over my system.

Even I'm not facing any problems on local system, the problem starts whenever I try to store the output file on a network machine.

Hi Manoj,


Thanks for your feedback.

I have again tested this scenario while using a Network folder to store the output PDF files and I am able to notice that ‘System.NullReferenceException’ is occurring while saving the output documents. For the
sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-33915. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We
apologize for your inconvenience.

Hi Manoj,


Thanks for your patience.

We have further investigating the issue related to saving the output to network path and as per our observations, the problem seems to be related to source PDF file (FormFieldTest_code_Button.pdf) which you are using. The source document seems to be corrupted. Besides this, when using the following code snippet with latest release of Aspose.Pdf for .NET 9.2.0. the PDF files are properly being saved to network locations. For testing purposes, I have used one of my sample PDF files.

[VB.NET]

Dim msOut As New MemoryStream()<o:p></o:p>

Dim Mender As New Facades.PdfFileMend("\\192.168.1.1\nayyer\\Pdf.pdf", "\\192.168.1.1\nayyer\\ComboBox_Field-With_Image.PDF")

Mender.AddImage("c:\\pdftest\\WordSplitacrossslines.png", 1, 100, 100, 200, 200)

Mender.Close()

Dim fsFinalOut As New FileStream("\\192.168.1.1\Share\\ComboBox_Field-With_Image-RemovedField.PDF", FileMode.Create, FileAccess.Write)

Dim fsFinalIn As New FileStream("\\192.168.1.1\Share\\ComboBox_Field-With_Image.PDF", FileMode.Open)

Dim myformeditor As New Aspose.Pdf.Facades.FormEditor(fsFinalIn, fsFinalOut)

myformeditor.RemoveField("AddedTextField")

myformeditor.Save()

fsFinalOut.Close()

'close input PDF

fsFinalIn.Close()

'open document

Dim fileStamp As New Facades.PdfFileStamp("\\192.168.1.1\Share\\ComboBox_Field-With_Image.PDF", "\\192.168.1.1\Share\\ComboBox_Field-With_Image-Stamped.pdf")

'create stamp

Dim stamp As New Aspose.Pdf.Facades.Stamp()

stamp.BindLogo(New Facades.FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, Aspose.Pdf.Facades.EncodingType.Winansi, True, 14))

stamp.SetOrigin(200, 200)

stamp.Rotation = 90.0F

stamp.IsBackground = True

'add stamp to PDF file

fileStamp.AddStamp(stamp)

'save updated PDF file

fileStamp.Close()