IbrahimMNada / TemplateToPdf.Demo

This is a demo applciation for Umbraco Template to Html
1 stars 3 forks source link

No such file or directory #3

Open craigs100 opened 2 years ago

craigs100 commented 2 years ago

Using the following in a Master page in a Umb 9.2.0 site

@using TemplateToPdf.Builders
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IPublishedContent>

var pdfUrl = new PdfUrlBuilder().UsingGetByIdMethod(Model.Id).WithTemplateAlias("ThreeColumnPage").AddPdfFileName(Model.Name).Url();

and in the footer:

<a target="_blank" href="@pdfUrl">See PDF</a>

The link is : http://localhost:9531/Umbraco/ToPdf/Convert/ById?id=32722&viewName=ThreeColumnPage&fileName=Welcome

When I hit the link I get :

Win32Exception: No such file or directory System.Diagnostics.Process.ForkAndExecProcess(string filename, string[] argv, string[] envp, string cwd, bool redirectStdin, bool redirectStdout, bool redirectStderr, bool setCredentials, uint userId, uint groupId, uint[] groups, out int stdinFd, out int stdoutFd, out int stderrFd, bool usesTerminal, bool throwOnNoExec)

The .exe is in place:- image

I'm running on Linux, is this a problem?

Regards,

Craig

craigs100 commented 2 years ago

I've since put this live onto a Windows server and Umbraco 10.0.1 (so that's dotnet 6.0.5) and get the same error. Any advice would be appreciated. Happy to help debug.

Regards,

Craig

IbrahimMNada commented 2 years ago

Hello, sorry for the late reply it was Al-Adha Eid Over here,

after you put the file into your solution you need to tell the application where is the file is located. you can do that in the start up class or on dot.net core 6 that's the program folder.

you can find more details on the getting started guide

services.AddTemplateToPdf(_env);

if you needed anything or any details please contact me any time

regards

craigs100 commented 2 years ago

Hi,

Thanks for your reply and I hope you had a nice holiday. :)

I dev on Linux and deploy to Windows. On Linux the site starts and only errors when the generated link is clicked. On Windows the site won't even start. It's stdout log shows:-

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Rotativa.AspNetCore, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Rotativa.AspNetCore, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.<>c.<GetApplicationPartAssemblies>b__8_0(ApplicationPartAttribute name)
   at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services, IWebHostEnvironment environment)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
   at Smidge.SmidgeStartup.AddSmidge(IServiceCollection services, IConfiguration smidgeConfiguration)
   at Umbraco.Extensions.UmbracoBuilderExtensions.AddRuntimeMinifier(IUmbracoBuilder builder)
   at Umbraco.Extensions.UmbracoBuilderExtensions.AddBackOffice(IUmbracoBuilder builder, Action`1 configureMvc)
   at TIUCL901.Startup.ConfigureServices(IServiceCollection services) in /home/craig/DotNetCoreSites/TIUCL901/Site/Startup.cs:line 42
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Umbraco.Cms.Web.Common.Hosting.UmbracoHostBuilderDecorator.Build()
   at TIUCL901.Program.Main(String[] args) in /home/craig/DotNetCoreSites/TIUCL901/Site/Program.cs:line 11

Program.cs line 11 is:-

      public static void Main(string[] args)
        => CreateHostBuilder(args) // line 11
          .Build()
          .Run();

The Startup.cs file section is:-

            services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddComposers()
                .Build();

            // For TemplateToPdf package
            services.AddTemplateToPdf(_env);

the .exe file is where it's supposed to be: "~/wwwroot/TemplateToPdf/" yet neither Windows (dotnet 6) or Linux (dotnet 5 & 6) can find it. If you have any other description of where it should be placed I'd love to hear it. I didn't understand "or on dot.net core 6 that's the program folder." in your reply.

I'd love to get this working as all the alternatives require a lot of effort and expense.

Thanks.

IbrahimMNada commented 2 years ago

Hello , can u please try and install a nuget package called "Rotativa".

and please tell me if it worked or no.

craigs100 commented 2 years ago

I added the Rotativa 1.7.3 package that said it was dependent on dotnet 5+. However, it wouldn't build. Get lots of these errors:-

/TFH/Site/Site.csproj : warning NU1701: Package 'Microsoft.AspNet.Mvc 5.2.3' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.

IbrahimMNada commented 2 years ago

Hello man,

sorry for the late reply i have tried to install template to pdf package on an umbraco 10 project every thing worked perfectly

i have uploaded the project for you on google drive in order to use it as example (its the same as the demo project)

https://drive.google.com/file/d/1roJ5I4YxZdp_fQppP00-_Q22C5vNqr1o/view?usp=sharing

back office credentials username: tupacmuhammad5@gmail.com password : Admin123456

IbrahimMNada commented 2 years ago

i think the issue with your application is that the line

services.AddTemplateToPdf(_env);

is referring somewhere else

image

try and follow the previous example in the link i have provided

Hope it works

craigs100 commented 2 years ago

Thanks for that. I have the project running here and when I click on one of your "See Resume Here" links I get the same error as in my very first post. I'm running on Linux and I suspect (but I might be wrong) that this package needs Windows to run successfully.

IbrahimMNada commented 2 years ago

you can override the path of the folder my best guess the that on Linux the _env file directory does not start in "wwwroot"

craigs100 commented 2 years ago

Thanks, I'll take a look at that when I'm back from holiday and report back. Would be good to know you can use it anywhere :)

IbrahimMNada commented 1 week ago

sorry for the late reply , is this done ?

rade-projects commented 1 week ago

Sorry, I had to move on at the time. However, I have a need for a PDF solution on my current project. I was going to use Puppeteer, but I'll give your's another go and let you know how it goes.

https://discord.com/channels/869656431308189746/1263879966588665858

IbrahimMNada commented 1 week ago

Provide me with more details please