I'm trying to flatten this interactive PDF that is based on the XML Forms Architecture (XFA):
http://www.finanse.mf.gov.pl/documents/766655/1481810/PIT-11(23)_v1-0E_2016.pdf
It contains Arial font with polish encoding.
After flattening it with the code below, I get a new PDF, but without Arial font and without polish letters of the original (FreeSans and Helvetica are used instead).
How can I make the flattened PDF include the same fonts as the original one?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using iTextSharp;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml.xtra.xfa;
using iTextSharp.text;
using iTextSharp.license;
namespace PdfFiller_bon
{
public class PdfFiller
{
public string LastError
{
get;
private set;
}
public PdfFiller()
{
LastError = "";
}
public bool FillPdfFromXml(string PdfSrc, string PdfDest, string XmlSrc, string licenseFile = "")
{
if (!File.Exists(PdfSrc))
{
LastError = "PDF Form does not exist";
return false;
}
if (!File.Exists(XmlSrc))
{
LastError = "XML file does not exist";
return false;
}
PdfReader reader = null;
PdfStamper stamper = null;
MemoryStream ms = null;
PdfWriter writer = null;
try
{
PdfReader.unethicalreading = true;
LicenseKey.LoadLicenseFile(licenseFile);
ms = new MemoryStream();
reader = new PdfReader(PdfSrc);
stamper = new PdfStamper(reader, ms);
stamper.Writer.CloseStream = false;
AcroFields form = stamper.AcroFields;
XfaForm xfa = form.Xfa;
xfa.FillXfaForm(new FileStream(XmlSrc, FileMode.Open));
stamper.Close();
Document document = new Document();
writer = PdfWriter.GetInstance(document, new FileStream(PdfDest, FileMode.Create));
FontFactory.Register("C:\\Windows\\Fonts\\Arial.ttf", "Arial");
Font font = FontFactory.GetFont("Arial", BaseFont.CP1250, BaseFont.EMBEDDED);
//TODO how to feed the font to the flattener?
XFAFlattener xfaf = new XFAFlattener(document, writer);
ms.Position = 0;
xfaf.Flatten(new PdfReader(ms));
document.Close();
writer.Close();
ms.Close();
}
return true;
}
}
}
I have a trial license code and am trying to work up a solution to decide if we should pay for the license.