'Pdf' does not exist in the namespace 'Syncfusion'

Hi,
My project is based on this sample:https://github.com/SyncfusionExamples/EJ2-DocumentEditor-WebServices/tree/master/ASP.NET%20Core. This means it is mostly equal to the linked sample, with the exception of theDocumentEditorController.cs file.
Currently, myDocumentEditorController.cs uses the following dependencies:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Text;
using System.IO;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Syncfusion.EJ2.DocumentEditor;
using WDocument = Syncfusion.DocIO.DLS.WordDocument;
using WDocumentProperty = Syncfusion.DocIO.DLS.DocumentProperty;
using WFormatType = Syncfusion.DocIO.FormatType;
using Syncfusion.EJ2.SpellChecker;
using EJ2APIServices;
When I try adding dependencies to make the .docx-to.pdf conversion possible, though, I get errors like this:
Controllers/DocumentEditorController.cs(21,22): error CS0234: The type or namespace name 'Pdf' does not exist in the namespace 'Syncfusion' (are you missing an assembly reference?) [/App/EJ2APIServices.csproj]

This errors were caused by trying to use this dependencies:
using Syncfusion.Pdf;
using
Syncfusion.DocToPDFConverter;
How can I make use of the PDF conversion in my project? If possible, a walktrough would be better, since I'm not a .NET developer at all.

3 Replies 1 reply marked as answer

SR Stephen Raj Chandra Sekar Syncfusion Team December 22, 2020 10:13 AM UTC

Hi Henrique, 
 
You have to install below package for converting the docx to pdf. 
 
 
Document editor content can be exported as PDF file with the help of DocIO library. 
 
please refer the below documentation for converting documents to PDF 
 
 
please refer the below code snippet in ASP.NET core. 
 
using Syncfusion.DocIORenderer; 
using Syncfusion.Pdf; 
 
        [HttpPost] 
        [Route("DocToPDF")] 
        public string DocToPDF() 
        { 
           IFormFile file = HttpContext.Request.Form.Files[0]; 
            Stream stream = new MemoryStream(); 
            file.CopyTo(stream); 
           stream.Position = 0; 
            Syncfusion.DocIO.DLS.WordDocument wordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx); 
            //Instantiation of DocIORenderer for Word to PDF conversion 
            DocIORenderer render = new DocIORenderer(); 
            //Converts Word document into PDF document 
            PdfDocument pdfDocument = render.ConvertToPDF(wordDocument); 
            //Saves the PDF file 
            FileStream fileStream = new FileStream(hostingEnvironment.WebRootPath + "\\Files\\" + "sample.pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite); 
            pdfDocument.Save(fileStream); 
            //Closes the instance of PDF document object 
            render.Dispose(); 
            wordDocument.Dispose(); 
            pdfDocument.Dispose(); 
            fileStream.Close(); 
            return "Success"; 
        } 
 
Kindly check it and let us know if you need any further assistance on this. 
 
Regards, 
Stephen Raj


HG Henrique Guerra December 22, 2020 10:01 PM UTC

Thank you, Stephan!

I was able to start the application up now, but when I call this route I'm getting this error:
System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSkiaSharp: cannot open shared object file: No such file or directory
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888()
   at SkiaSharp.SKImageInfo..cctor()

This is my code:
[AcceptVerbs("Post")]
[HttpPost]
[EnableCors("AllowAllOrigins")]
[Route("ToPdf")]
public FileStreamResult ToPdf(IFormCollection data)
{
if (data.Files.Count == 0)
return null;

IFormFile file = data.Files[0];
string fileName = GetFileName(file);
string pdfName = $"{fileName}.pdf";

using (WDocument word = GetDocument(file))
{
DocIORenderer converter = new DocIORenderer();
PdfDocument pdf = converter.ConvertToPDF(word);
converter.Dispose();
word.Close();
word.Dispose();

MemoryStream output_stream = new MemoryStream();
pdf.Save(output_stream);
pdf.Close();
pdf.Dispose();
output_stream.Position = 0;

//Download Pdf document in the browser
return File(
output_stream,
"application/pdf",
pdfName
);
}
}

I have tried installing some packages (SkiaSharp, SkiaSharp.Linux, SkiaSharp.NativeAssets.Linux), as well as adding this to my Dockerfile:
# Install necessary fonts for docx-to-pdf conversion
RUN apt-get update -y && apt-get install libfontconfig -y
RUN echo "deb http://httpredir.debian.org/debian buster main contrib non-free" > /etc/apt/sources.list \
&& echo "deb http://httpredir.debian.org/debian buster-updates main contrib non- free" >> /etc/apt/sources.list \
&& echo "deb http://security.debian.org/ buster/updates main contrib non-free" >> /etc/apt/sources.list \
&& echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections \
&& apt-get update \
&& apt-get install -y \
fonts-arphic-ukai \
fonts-arphic-uming \
fonts-ipafont-mincho \
fonts-ipafont-gothic \
fonts-unfonts-core \
ttf-wqy-zenhei \
ttf-mscorefonts-installer \
&& apt-get clean \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*

Do you have any idea how to fix this?

P.S.: I'm running the service on a Linux Docker image.


SR Stephen Raj Chandra Sekar Syncfusion Team December 23, 2020 11:06 AM UTC

Hi Henrique,

 

We suspect that the issue might be due to conflicts in SkiaSharp graphics library. Please remove all the SkiaSharp NuGets in your application and install SkiaSharp.NativeAssets.Linux v2.80.2 NuGet to resolve this issue.

 

Regards,

Stephen Raj

Marked as answer
Loader.
Up arrow icon