I am trying to use Aspose to set the values of fields in a pdf. This pdf works fine in ITextSharp. That is the main frustration I am experiencing.
Here's my code
string outputPdf = String.Format(#"C:\PDF\output\test{0:dd-MM-yyyy-HH-mm-ss}.pdf", DateTime.Now);
string inputPdf = #"C:\PDF\application.pdf";
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(inputPdf, outputPdf);
form.FillField("MY_FIELD", "Test Value");
form.FlattenAllFields();
form.Save();
the line Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(inputPdf, outputPdf); is causing an error.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Here's the stacktrace
[NullReferenceException: Object reference not set to an instance of an object.]
Aspose.Pdf.EmbeddedFileCollection.( node, Hashtable hash) +57
Aspose.Pdf.EmbeddedFileCollection..ctor(Document document) +161
Aspose.Pdf.Document.() +58
Aspose.Pdf.Document.(Stream input, String password) +181
Aspose.Pdf.Facades.Form..ctor(String srcFileName, Stream destStream) +92
I posted on their forums and it appears Aspose.Pdf 6.0.0 has known bugs due to a project merge between Aspose.Pdf and Aspose.Pdf.Kit. I am unable to open a Document or access the form in 6.0.0, so I grabbed Aspose.Pdf.Kit 5.6.0 and I was able to make it work.
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(inputPdf, outputPdf);
form.FillField("MyField", "Some Value");
Hope that helps anyone else who tries to use their software. After I did that, everything works fine for my demo version.
Have you tried Aspose.Pdf for .NET 6.2.0? Our team is also reviewing the upcoming version 6.3.0 which will be published in a week. Please try the latest one. If you still find any such issue please report it along with the input PDF file in Aspose.Pdf forum so our team could help you resolve this issue.
Disclosure: I work as developer evangelist at Aspose.
Related
string docuAddr = #"C:\Users\psimmon\source\repos\PDFTESTAPP\PDFTESTAPP\TempForms\forms-www.courts.state.co.us-Forms-PDF-JDF1117.pdf";
byte[] bytes = Encoding.Unicode.GetBytes(docuAddr);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(bytes, true);---blows here
PdfLoadedForm myForm = loadedDocument.Form;
PdfLoadedFormFieldCollection fields = myForm.Fields;
not sure what I have done wrong here, but the PDF file is opening, either in a browser or a fileexployer window. so it has to be me, guessed at most of this, all you very smart folks, I could use your gray matter. forgive my stupidity.
The reported exception “could not find valid signature (%PDF-)” may occurs due to the file is not a PDF document. We suspect it seems the other format files are saved with the “.pdf” extension. We could not open and repair this type of document on our end, we have already added the details in our documentation,
Please find some of the following corrupted error messages that cannot be repaired:
UG: https://help.syncfusion.com/file-formats/pdf/open-and-save-pdf-file-in-c-sharp-vb-net#possible-error-messages-of-invalid-pdf-documents-while-loading
If you want to find this type of corrupted document, Syncfusion PDF Library provides support to check and report whether the existing PDF document is corrupted or not with corruption details and structure-level syntax errors.
UG: https://help.syncfusion.com/file-formats/pdf/working-with-document#find-corrupted-pdf-document
Blog: https://www.syncfusion.com/blogs/post/how-to-find-corrupted-pdf-files-in-c-sharp.aspx
KB: https://www.syncfusion.com/kb/9686/how-to-identify-the-corrupted-pdf-document-using-c-and-vb-net
I have a purchased license to use ImageResizer.Sqlreader, I have it working on one section of my site already, and now I'm trying to get it working on a separate section of our site. On my AddImage page (on localhost), the debugger is barfing on a line of code that says:
ImageBuilder.Current.Build(file, ms, resizeCropSettings)
It throws me to an error that says "Source Not Found" and "LicenseService.cs not found". "You need to find LicenseService.cs to view the source for the current call stack frame."
I have the same ImageResizer NuGet packages installed in this project as I do in my already working project:
ImageResizer v4.0.5
ImageResizer.WebConfig v4.0.5
ImageResizer.Storage v4.0.5
ImageResizer.Sqlreader v4.0.5
Gist of diagnostics page
Usage context
Dim resizeCropSettings As New ResizeSettings("maxwidth=1600&maxheight=1600&format=jpg&autorotate=true")
Using ms As New MemoryStream()
' Resize the image
ImageBuilder.Current.Build(file, ms, resizeCropSettings) ' *** Fails to step through here
bytData = ms.ToArray()
End Using
Can you please advise? Thanks in advance.
The ImageResizer code in this question was working properly. The problem was due to an error in my code to save the Image item to the database (type mismatch). Setting the breakpoint as Nathanael suggested allowed me to debug past the "LicenseService.cs not found" error.
may I know how to use old iText(very old version under 0.99, package path = com.lowagie.xxx) to create bookmarks to jump in the internal pdf pls?
like the api in new iText jar:
PdfOutline outoline2 = com.itextpdf.pdf.PdfAction.gotoLocalPage("destinationName", false)
we have found below code to create bookmark, but find old iText needs to use the filename(see outFileName in below code). but what we want is a jump in internal pdf (not remote pdf)
olineSignature = new PdfOutline(root, new PdfAction(outFileName, "Signature2TxtDestination"), "Signature2TxtOutline");
FYI, we don't know what page number in advance, so no way to use the api as below: old PdfAction.gotoLocalPage(int, PdfDestination, PdfWriter)
anybody can help me? Thanks.#Bruno Lowagie, #itext :)
We are in the progress of upgrading to new iText(itext5+), but now we do get a request to create bookmarks(using old iText) for others to retrieve the created bookmarks.
My memory can't go that far back but local destinations are most probably not supported. Your only chance is to do an interim upgrade to the Jurassic 2.1.7 that should be more or less compatible with that Pleistocene 0.99.
I am receiving the EI not found error in this specific pdf found under https://bfs.ever-team.com/files/6fce4cef9769e40d1994e684a881d4bf/facture3_1.pdf.
I am using itextpdf-5.4.3 jar and below is the code:
com.itextpdf.awt.geom.Rectangle rec = new com.itextpdf.awt.geom.Rectangle(307, 728, 742, 400);
RenderFilter filter = new RegionTextRenderFilter(rec);
TextExtractionStrategy strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter);
String currentText = PdfTextExtractor.getTextFromPage(reader, i , strategy);
Method getTextFromPage is returning the error,
I checked other threads but it was mentioned that this error should be fixed in the latest jar, but it seems it is not facture3_1.pdfworking for my file.
Can anyone advise please.
A crosspost of this question has been answered on the iText mailing list. To close the question here, too, that answer is copied here:
The issue can be reproduced with iText 5.4.3 but not with the current development snapshot. The OP, therefore, should update his iText version.
InlineImageParseException: EI not found after end of image data
EI denotes the end of an inline image. The handling of inline images is tricky and not strictly well-defined. iText recently improved its handling of inline images to correctly parse more PDFs with such inline images.
I'm trying to execute the following code:
PdfReader reader = new PdfReader("/path/to/file.pdf");
int pages = reader.getNumberOfPages();
It works on most files, but on one particular file, it crashes with error:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2882)
at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
at java.lang.StringBuffer.append(StringBuffer.java:320)
at com.itextpdf.text.pdf.PRTokeniser.readString(PRTokeniser.java:158)
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:224)
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:229)
...goes on for a while
at com.itextpdf.text.pdf.PRTokeniser.getStartxref(PRTokeniser.java:229)
I know that it's something wrong with the input file. I'm just wondering if there's a way of knowing before attempting to make the method call, that the file is going to cause a problem.
It turns out it was a bug with the version of itext I am using (5.0.1). I logged a query with the developers, and a fix was put in - that I tested - and which hopefully will find it's way into the next version (5.0.2)