ITextSharp with Windows 10 Universal App

Is there a way to get iTextSharp to work with the universal Windows 10 application? 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 a platform such as x64 or x86. We use iTextSharp in the Windows 8 Store application to take a PDF template and then fill in the fields with user-provided data. The user also provides a template so that the document is formatted the way he wants it. To do this, we again use 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 Windows 10 or any suggestions on how to generate a PDF from a template without iTextSharp would be greatly appreciated. Thanks,

+4
source share
2 answers

The UWP framework is apparently an update to the .NET ecosystem, especially in terms of security and cryptography. For example, in UWP, the hash algorithm classes are located in the Windows.Security.Cryptography.Core namespace, and before .NET 4.x they are in System.Security.Cryptography . Some classes have also been renamed.

This is a modified change for iTextSharp, as well as for its security dependency, BouncyCastle, because the System.Security.Cryptography assembly is used for digital signatures. NuGet or UWP seem to be aware of .NET assemblies that are being used and refuse to add dependencies that will not compile into UWP, regardless of whether you use any iTextSharp features related to digital signatures.

FYI I am an employee of iText, and we discovered this problem just a few weeks ago. The investigation is still ongoing, so I may not understand everything in this explanation. We are also working on a support strategy for both UWP and .NET 4.x - which, as I understand it, are mutually exclusive when it comes to cryptography. If you use Google the term "is not compatible with UAP" , then you can read about similar problems for many well-known libraries, so this is not only a problem for iTextSharp.

EDIT

If you really need a solution quickly, you can download the source code of iTextSharp and copy it into a new UWP class library project in Visual Studio. The number of compilation errors looks daunting, but about 80% of them seem trivial to me. for example, Half of them are references to Serializable and SerializationInfo in the inherited constructor of Exception classes that no longer exist, so they can be () deleted safely.

An alternative is to wait for the new version of iTextSharp, for which there is currently no (planned January 6, 2016) release date. In addition, to be clear, no decision has been made as to whether and how to support UWP with the next version or any next version in iTextSharp.

EDIT 2

I recently wrote a blog post about this issue as an official expression of the iText team. http://itextpdf.com/blog/itextsharp-and-uwp

+6
source

In uwp with c # are there any sdk that provide pdf editor function in c #

0
source

Source: https://habr.com/ru/post/1011683/


All Articles