Is there a way to get iTextSharp to work with a Windows 10 Universal app? When I try to add iTextSharp version 5.5.8 through the NuGet package manager I get the following errors:
iTextSharp 5.5.8 is not compatible with UAP, Version=v10.0(win10-XXX)
Some packages are not compatible ith UAP,Version=v10.0(win10-XXX)
Where XXX is the platform like x64 or x86. We use iTextSharp in a Windows 8 Store app to take a PDF template and then populate the fields with data provided by the user. The user also provides the template so the document is formatted the way they want it. For this we re using the PDFStamper class from the iTextSharp library to do this as shown in the following code:
public async Task<byte[]> fillPDF(string templatePath, FormData mergeDataItems)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(templatePath);
var buf = await FileIO.ReadBufferAsync(file);
var reader = new PdfReader(buf.ToArray());
var outStream = new MemoryStream();
var stamper = new PdfStamper(reader, outStream);
var form = stamper.AcroFields;
form.GenerateAppearances = true; //Added this line, fixed my problem
var fieldKeys = form.Fields.Keys;
foreach (KeyValuePair<String, String> pair in mergeDataItems.MergeFieldValues)
{
if (fieldKeys.Any(f => f == pair.Key))
{
form.SetField(pair.Key, pair.Value);
}
}
stamper.Close();
reader.Close();
return flattenPdf(outStream.ToArray());
}
and here
private static byte[] flattenPdf(byte[] pdf)
{
var reader = new PdfReader(pdf);
var outStream = new MemoryStream();
var stamper = new PdfStamper(reader, outStream);
stamper.FormFlattening = true;
stamper.Close();
reader.Close();
return outStream.ToArray();
}
Any help with getting iTextSharp to work with a windows 10 app or any suggestions on how to generate a PDF document from a template without iTextSharp would be greatly appreciated. Thanks,