Hello,
I'm trying to merge several PDF files into one and then print them.
I am using version 2022.2.621.
My code looks like this
My problem is, that befor print pdf looks like this

But after print

What I discoverd, that file befor print has more fonts then after.
Befor:

After

How can I handle this problem?
I'm trying to merge several PDF files into one and then print them.
I am using version 2022.2.621.
My code looks like this
public static void Print(List<string> files)
{
using (MemoryStream stream = new MemoryStream())
{
using (PdfStreamWriter fileWriter = new PdfStreamWriter(stream, leaveStreamOpen: true))
{
foreach (string path in files)
{
using (PdfFileSource fileSource = new PdfFileSource(new MemoryStream(File.ReadAllBytes(path))))
{
for (int i = 0; i < fileSource.Pages.Length; i++)
{
PdfPageSource sourcePage = fileSource.Pages[i];
using (PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size))
{
// set content
resultPage.WriteContent(sourcePage);
}
}
}
}
}
var pdfViewer = new RadPdfViewer();
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(stream);
pdfViewer.Document = document;
var printdlg = new PrintDialog();
printdlg.UserPageRangeEnabled = true;
printdlg.SelectedPagesEnabled = true;
if (printdlg.ShowDialog() == true)
{
var printSettings = new PrintSettings(Path.GetFileNameWithoutExtension("file"), false);
pdfViewer.Print(printdlg, printSettings);
}
}
}
My problem is, that befor print pdf looks like this
But after print
What I discoverd, that file befor print has more fonts then after.
Befor:
After
How can I handle this problem?
When I replace font with my own it works
var fontData = File.ReadAllBytes(@"...\helvetica-255\Helvetica.ttf"); FontsRepository.RegisterFont(new FontFamily("Helvetica"), FontStyles.Normal, FontWeights.Bold, fontData); FontsRepository.TryCreateFont(new FontFamily("Helvetica"), FontStyles.Normal, FontWeights.Bold, out var helvetica1); //Appy the font to the text fragments in the document foreach (RadFixedPage page in xx.Pages) { foreach (ContentElementBase contentElement in page.Content) { if (contentElement is Telerik.Windows.Documents.Fixed.Model.Objects.Form form) { foreach (var f in form.FormSource.Content) { if (f is Telerik.Windows.Documents.Fixed.Model.Objects.Form ff) { foreach (var f1 in ff.FormSource.Content) { if (f1 is TextFragment textFragment) { if (textFragment.Font.Name == "Helvetica") { textFragment.Font = helvetica1; } else if (textFragment.Font.Name == "Verdana,Bold") { // textFont = verdanaBold; } } } } } } } }
Hello John,
Thank you for the follow-up feedback. Please correct me if I am wrong, but from what I understand, you were able to resolve the issue on your own. It is indeed possible that some fonts might not support certain characters, so switching to other fonts that do provide this support can always serve as a workaround.
Regards,
Yoan