Error when using Documents processing and PdfViewer within the same project

1 Answer 256 Views
PdfProcessing
Sergey
Top achievements
Rank 1
Iron
Sergey asked on 02 Jan 2024, 04:33 PM

My C# project targets net6.0-windows and enables windows forms:

<PropertyGroup>
 <TargetFramework>net6.0-windows</TargetFramework>
 <ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
 <Nullable>enable</Nullable>
 </PropertyGroup>

In the code, I want to create PDF documents dynamically and show them by using the PdfViewer component.

Thus, I added the following references:

<PackageReference Include="Telerik.Documents.Core" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Fixed" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Flow" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Flow.FormatProviders.Pdf" Version="2023.3.1106" />
<PackageReference Include="Telerik.Zip" Version="2023.3.1106" />
<PackageReference Include="UI.for.WinForms.AllControls.Net60" Version="2023.3.1114" />

Here is a part of my code:


    internal class GenericPdfCombiner : IPdfCombiner
    {
        public RadFixedDocument Combine(List<string> fileNames)
        {
            using MemoryStream stream = new MemoryStream();
            using (PdfStreamWriter fileWriter = new PdfStreamWriter(stream, leaveStreamOpen: true))
            {
                for (var fi = 0; fi < fileNames.Count; fi++)
                {
                    var file = fileNames[fi];
                    using PdfFileSource fileSource = new PdfFileSource(new MemoryStream(File.ReadAllBytes(file)));
                    for (var p = 0; p < fileSource.Pages.Length; p++)
                    {
                        PdfPageSource sourcePage = fileSource.Pages[p];
                        using PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size);
                        resultPage.WriteContent(sourcePage);
                    }
                }
            }
            PdfFormatProvider provider = new PdfFormatProvider();
            return provider.Import(stream);
        }
    }

but it shows the error Reference to type 'Size' claims it is defined in 'WindowsBase', but it could not be found on the lines like the following:

using PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size);

How can I fix it?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Jan 2024, 06:03 AM

Hi, Sergey,

Following the provided information, I can say that the observed behavior is expected. This is because the Telerik’s Document Processing libraries (SpreadProcessing, WordProecessing or PdfProcessing) are referencing assemblies which are used in WPF.

In a .NET Framework project, a reference to WindowsBase is required to be added:

pdfviewer-highlight-form-fields 002

In a .NET Core (or newer version), it is necessary to edit the .proj file and include WPF:

pdfviewer-highlight-form-fields 003

pdfviewer-highlight-form-fields 004

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
Sergey
Top achievements
Rank 1
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or