I tried to create method for converting SVG to PDF/A using iText7. All this code is wrote in C# on .Net platform.
using (StreamReader reader = new StreamReader(svgFile.OpenReadStream()))
{
string svgContent = reader.ReadToEnd();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(svgFile.OpenReadStream());
if (xmlDocument.DocumentElement != null && xmlDocument.DocumentElement.Name == "svg")
{
using (MemoryStream pdfStream = new MemoryStream())
{
// Create PDF/A compliant document
PdfADocument doc = new PdfADocument(
new PdfWriter(pdfStream, new WriterProperties().SetCompressionLevel(0)),
PdfAConformanceLevel.PDF_A_1A,
new PdfOutputIntent("Custom"
, "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream("sRGB_ICC_v4_Appearance.icc", FileMode.Open, FileAccess.Read))
);
PdfFont timesRomanFont = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED, doc);
PdfCatalog catalog = doc.GetCatalog();
PdfDictionary markInfo = new PdfDictionary();
markInfo.Put(PdfName.Marked, PdfBoolean.TRUE);
catalog.Put(PdfName.MarkInfo, markInfo);
PageSize pageSize = PageSize.A4.Rotate();
doc.SetDefaultPageSize(pageSize);
doc.AddNewPage();
PdfCanvas canvas = new PdfCanvas(doc.GetLastPage());
canvas.SetFontAndSize(timesRomanFont, 12);
// Scale transformation
float scaleX = 0.707f; // Adjust as needed
float scaleY = 0.707f; // Adjust as needed
// Apply the scaling transformation to the canvas
canvas.ConcatMatrix(scaleX, 0, 0, scaleY, 0, 0);
//Change color mode
XmlDocument modifiedXmlDocument = SvgColorTransformer.ApplyColorTransformation(xmlDocument, colorMode);
string modifiedSvgContent = modifiedXmlDocument.OuterXml;
SvgConverter.DrawOnDocument(svgContent, doc, 1);
doc.Close();
return pdfStream.ToArray();
}
}
else
{
throw new BadRequestException("Invalid SVG format");
}
}
Is this possible to change Times-Roman to other font that will work? Or is this default font of PDF/A? Even if i tried force embedded here:
PdfFont timesRomanFont = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED, doc);
I got this error message: Standard fonts cannot be embedded.