FlattenFields is not working as expected - itext7

We have been working on a POC with IText7 and getting an error when we try to FlattenFields. All we are trying to do is load a pdf template and inject values. The template which we are using was working fine with IText5.
Here is the exception message:
An exception of type 'iText.Kernel.PdfException' occurred in itext.kernel.dll but was not handled in user code
Additional information: unbalanced.begin.end.marked.content.operators
using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(fileName), new PdfWriter(outputStream)))
{
PdfAcroForm stamper = PdfAcroForm.GetAcroForm(pdfDoc, true);
stamper.FlattenFields();
stamper.SetGenerateAppearance(true);
}
Regards
Shreenidhi B.R

Followed up with IText support folks and they said that this issue has been fixed in IText 7.0.1. I haven't had a chance to test it myself though.

Related

Getting pdf signatures with iText7

I have a scenario where I need to get signature information from a pdf with the iText7 library. The signature may or may not exist. When I instantiate a new SignatureUtil object for a PDF that does not have any digital signatures I get the exception
"There is no associate PdfWriter for making indirects."
. If an signature is there it works fine. I'm not sure how to correct this exception.
UPDATED to include code sample
Using reader As New PdfReader(pdfPath),
pdf As New PdfDocument(reader)
Dim util As New SignatureUtil(pdf)
Dim signModel As String = "[Signature: {0} - {1}]"
For Each signame As String In util.GetSignatureNames()
Dim whoisthis As PdfSignature = util.GetSignature(signame)
returnVal &= String.Format(
signModel,
whoisthis.GetName(),
whoisthis.GetReason
)
Next
End Using
The exception is thrown because there is no AcroForm in the document and SignatureUtil tries to add it, but there is no associated PdfWriter.
As a workaround you can check if a document contains an AcroForm:
PdfAcroForm.getAcroForm(document, false) != null
And only create SignatureUtil if there is an AcroForm. If there is no AcroForm there will be no signature fields.

EWS Managed API 2, setting FlagStatus

I'm attempting to set the Flag on an e-mail using EWS Managed API 2 - however, I keep getting an error that I can't seem to get past.
I'm doing the following:
ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
exchangeService.Url = new Uri(<ews url comes from Outlook JavaScript API>);
exchangeService.UseDefaultCredentials = false;
exchangeService.Credentials = new OAuthCredentials(<ews token comes from Outlook JavaScript API>);
And then a little later:
Item item = Item.Bind(exchangeService, new ItemId(<mail id comes from Outlook JavaScript API>), new PropertySet(ItemSchema.Flag));
item.Load();
item.Flag = new Flag() { FlagStatus = ItemFlagStatus.Flagged };
item.Update(ConflictResolutionMode.AutoResolve);
What am I missing?
I keep getting this error:
You must load or assign this property before you can read its value.
UPDATE: Ok, it turned out the this error was caused by some other code which has been corrected.
Now I'm getting this error instead:
The requested web method is unavailable to this caller or application.

itext XFA: InvalidCastException

Using itext7 and when trying to load XFA form I'm getting:
System.InvalidCastException: 'Unable to cast object of type
'System.Xml.Linq.XText' to type 'System.Xml.Linq.XElement'.'
Source code:
var pdfReader = new PdfReader(package.PdfTemplate);
pdfReader.SetUnethicalReading(true);
using (var document = new PdfDocument(pdfReader, new PdfWriter(writeMS)))
{
var acroForm = PdfAcroForm.GetAcroForm(document, true);
var xfa = acroForm.GetXfaForm();
var dataXml = _dataGenerator.GenerateXfaFormData(package);
xfa.FillXfaForm(dataXml);
xfa.Write(document);
}
The exception is thrown on line
var acroForm = PdfAcroForm.GetAcroForm(document, true);
Sample PDF can be seen here: https://programmcze-my.sharepoint.com/personal/nechanicky_programmcze_onmicrosoft_com/_layouts/15/guestaccess.aspx?docid=0c18710068a124a58a32e77ad53c4cbb9&authkey=AQvVBZLXNirrISLjvT083XY
There indeed was a problem with constructing XfaForm which does not contain <xfa:datasets> entry.
The problem is fixed in iText 7.0.5-SNAPSHOT version. The repository with the sources and the fix can be found here.

ASP.NET BoilerPlate: .Net core template - app service error

I am in the process of moving my app code from the .Net5 MVC/JQuery ASPNETZERO template to the new .Net core 1.1 MVC/JQuery template.
So far I have copied over my first few custom entities. Created a EF migration and applied the changes to my DB.
I then started building the first app service for one of my entities. I am copying over the code from my existing MVC template that is working without any issues.
public async Task<PagedResultDto<ListValuesListDto>> GetListValues(GetListValuesInput input)
{
var query = from lv in _listvaluesRepository2.GetAll()
select new ListValuesListDto
{
Id = lv.Id,
ListName = lv.ListName,
ListText = lv.ListText
};
query = query.WhereIf(!input.Filter.IsNullOrWhiteSpace(), lv => lv.ListName.Contains(input.Filter) || lv.ListText.Contains(input.Filter));
var resultCount = await query.CountAsync();
var results = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();
return new PagedResultDto<ListValuesListDto>(resultCount, results);
}
The method above is from my MVC template. When I place this into the .Net core solution, I keep getting the following build error.
CS0411 The type arguments for method 'Enumerable.OrderBy(IEnumerable, Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly
The error is pointing to the "OrderBy" on this line of code:
var results = await query.OrderBy(input.Sorting).PageBy(input).ToListAsync();
I am still very much learning the ABP template and EF. I cannot for the life of me figure out why the same code in the .Net core template does not work?
Any help that anyone can provide would be much appreciated!
I just solved my own issue. I had to add the using statement for System.Linq.Dynamic.Core
Hope it helps someone else! :-)

How do I replace an existing Community file on IBM SmartCloud

I am trying to replace an existing Community file using the following java
Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("createVersion", "false");
fileEntry = fileService.updateCommunityFile(fis, fileUuid, fileName, communityLibraryId, paramsMap);
But it is returning a HTTP 411:Length required error.
I am using the latest build (1.1.5.20150520-1200.jar)
Does anyone have a suggestion as to what i am missing?
I tried recreating the issue but I am able to upload New version of Community file correctly with and without version, using the updateCommunityFile API. I do not get any Length related error. This is the snippet I am using :
java.io.File file = new java.io.File("C://TestUploadCommunity.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
} catch (Exception e) {
//TODO
}
fileEntry = fileService.updateCommunityFile(fis, fileEntry.getFileId(), fileEntry.getLabel(), communityLibraryId, params);
Can you share more details on your sample, what exactly is your fis?
I have tried this on 2 environments and I do not see any issue.
Also, from the entry you have pasted,
"Request to url apps.na.collabserv.com/files/basic/api/library... /document/... /entry?content-length=6600&createVersion=false returned an error response 411:Length Required HTTP/1.1 411"
It seems that somehow an incorrect content-length is passed for your request.
Can you share the sample that you are using?

Resources