Git Product home page Git Product logo

wkhtmltopdf.netcore.example-deprecated's Introduction

wkhtmltopdf.netcore.example-deprecated's People

Contributors

fpanaccia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wkhtmltopdf.netcore.example-deprecated's Issues

/app/{GUID}.pdf file not found exception in Linux Docker Compose on .NET5

Using Wkhtmltopdf.NetCore 5.0.2-preview

I'm getting an exception of pdf file not found while running on docker-compose linux container.
I can see an html file created in the root directory(/app) of the container. But it is not being able to generate pdf out of if.
Exception I'm getting is below

Could not find file '/app/c4a6d426-1cd8-4e08-90c3-64067b1b9a56.pdf'.

at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(String wkhtmlPath, String switches, String html)
at Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(String html)

How to pass a string argument to wkhtmltopdf?

I'm trying to convert another package to Wkthmltopdf, but I could not find a way to pass a string argument to wkthmltopdf executable.

In my conversion, I have an argument "--disable-smart-shrinking -T 30 -B 35 --footer-right "page [page] / [topage]" --footer-font-size 9"

I just like to send this exact string to the executable. How can I do this?

Rotativa Container

I am trying to create a container but it shows me the following error. Any suggestion please? See here. Thanks

Images

Good day everyone,

Can someone help me with displaying Image in PDF...

Permission Denied on Mac

I try to execute the exemple on mac but i get this error.

Win32Exception: Permission denied
Wkhtmltopdf.NetCore.WkhtmlDriver.Convert(string wkhtmlPath, string switches, string html)
Wkhtmltopdf.NetCore.GeneratePdf.GetPDF(string html)
Wkhtmltopdf.NetCore.GeneratePdf.GetPdf(string View, T model)
Rotativa.Controllers.TestViewsController.GetSSL() in TestViewsController.cs
+
return await _generatePdf.GetPdf("Views/TestBootstrapSSL.cshtml", data);
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Not working with .net core 3.0

Hi fpanaccia,

Great solution however it doesn't work with .net ocre 3.0.

I wonder if we can get .net core 3.0 compatible package of it.

Regards,
MS

How can I set the document name

Hi

Have been trying to set a name for the document generated using the _generatePdf.GetByteArrayViewInHtml(). Please how can I go about this? Instead of the Document given as the default title when you preview or download, I want to be able to change it.

Screenshot (73)

Thanks.

Can't use library with View in dotnet core 3.1

Hi, I'm testing the library on a Windows 10 environment with dotnet core 3.1.
Tests using the GetPDF method work.
Tests using a view fail.

This is the code:

        public async Task<IActionResult> GetByteArray()
        {
            var data = new Panel
            {
                Descr = "This is a test",
                Id = 123456
            };

            var pdf = await _generatePdf.GetByteArray<Panel>("Views/Test.cshtml", data);
            var pdfStream = new System.IO.MemoryStream();
            pdfStream.Write(pdf, 0, pdf.Length);
            pdfStream.Position = 0;
            return new FileStreamResult(pdfStream, "application/pdf");
        }

image

error when save pdf on linux

screen-1659637002

Code:

    public async Task<UploadedFileInformation> RenderPdf<T>(string module, string vista, T format)
    {
        string pathFolder = Path.Combine(storage, $"{file.Id}-{file.Name}");
        byte[] pdf = await _generatePdf.GetByteArray($"Modules/{module}/Views/{vista}.cshtml", format);
        File.WriteAllBytes(pathFolder, pdf);

@fpanaccia help me pleace

Unable to resolve service for type 'Wkhtmltopdf.NetCore.IGeneratePdf'

Hello !!
I'm flowing this blog But having issue bcs DI could not find
IGeneratePdf

System.InvalidOperationException: Unable to resolve service for type 'Wkhtmltopdf.NetCore.IGeneratePdf' while attempting to activate 'test.Controllers.WeatherForecastController'

here I have supplied .exe and register Wkhtmltopdf in services
image

this is controller code
image

Not working with Areas view

Its working totaly fine with root views but not working or finding view in Area folders

 EmailModel model = new EmailModel();
                model.Agent = flight;
                model.Company = _companyMasterService.GetActiveCompany();
                var options = new ConvertOptions
                {
                    PageMargins = new Wkhtmltopdf.NetCore.Options.Margins()
                    {
                        Left = 10,
                        Right = 10,
                        Top = 10,
                        Bottom = 10,
                    }
                };

                _generatePdf.SetConvertOptions(options);
                
                var actionPdf = await _generatePdf.GetByteArray("Agent/Views/Email/Index.cshtml", model);

                System.IO.File.WriteAllBytes(Path.Combine(_webHostEnvironment.WebRootPath, "Log\\Agentpdf", "Ticket_" + id + ".pdf"), actionPdf);

                path = System.IO.Path.Combine(_webHostEnvironment.WebRootPath, "Log\\Agentpdf\\Ticket_" + id + ".pdf");
                var net = new System.Net.WebClient();
                var data = net.DownloadData(path);
                var content = new System.IO.MemoryStream(data);
                return File(content, GetContentType(path), Path.GetFileName(path));

What is wrong i have done?

Permission Denied Issue For Linux

Hi everyone,

I've been having this permission error when I deploy on the Linux environment in Docker + Kubernetes using Azure Dev Spaces

Exception Permission Denied
TargetSite at Wkhtmltopdf.NetCore.GeneratePdf.GetByteArrayViewInHtml(String ViewInHtml)

I have run this RUN chmod 755 on the path where the Linux distribution runner is located

Please come to my aid

Problem on MacOS

I try to run wkhtmltopdf on macOS 10.15.5 and my error is:

An exception of type 'System.ComponentModel.Win32Exception' occurred in Wkhtmltopdf.NetCore.dll but was not handled in user code: 'Bad CPU type in executable'

I don't know what can be wrong.

Footer issue and documentation on using 'default params'

I have some legal documents that I'm having to recreate in PDF from a .Net 5 (core) MVC application (using wkhtmltopdf.netcore 3.0.2). Obviously, I'm using your tool and for the most part, it's worked great. However, when it comes to footers, my legal docs have special conditions for footers. Like some pages not having paging and others resetting the starting page when a new section is encounters. With that being said, how do you use the "url" and special parameters that you've given us? How does using the "section" parameter work? I can't get it too. Section is always blank.

https://localhost:44342/footer.html?
page=1&section=&sitepage=1&title=&subsection=&username=Veaer&url=google.com&frompage=1&subsubsection=&age=20&isodate=2022-02-
14&topage=20&doctitle=&sitepages=20&webpage=-&time=3:10:34%20PM&date=2/14/2022

I'm behind on a project due to this footer issue and we might have to bail on using this tool. Any help would be awesome!
Thanks

[BUG] GetByteArrayViewInHtml(view, model) not working.

Bug Information

Version Number of Plugin: 3.0.2
Version of VS: Microsoft Visual Studio 2019 V. 16.6.5
Target Framework: .NET Core 3.1

Steps to reproduce the Behavior

  1. Add services.AddWkhtmltopdf(); to startup.
  2. Add IGeneratePdf to constructor.
  3. Call GetByteArrayViewInHtml(view, model) and receive the respective value for the pdf generated.

Expected Behavior

Calling GetByteArrayViewInHtml(view, model) should return the pdf generate in a byte array format.

Actual Behavior

Calling GetByteArrayViewInHtml(view, model) instead throws the below exception:

Could not find an IRouter associated with the ActionContext. If your application is using endpoint routing then you can get a IUrlHelperFactory with dependency injection and use it to create a UrlHelper, or use Microsoft.AspNetCore.Routing.LinkGenerator.

Code snippet

This is the snippet in my controller:

var resPDF = await _pdfGenerator.GetByteArrayViewInHtml<ReportInEditViewModel>("PDFTemplates/Report", model);

This is a section of my view:

@model ViewModels.ReportInEditViewModel
@{  Layout = null; }

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="~/lib/fontawesome/css/all.min.css" />
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/lib/fontawesome/js/all.min.js"></script>
</head>
<body>
   ...
</body>
</html>

Final Comments

Any help would be greatly appreciated! ๐Ÿ˜‰

header-html using MVC view is not working

 var options = new ConvertOptions();
  if (isvalid)
  {
      options.HeaderHtml = $"https://localhost:121165/Areas/Controller/GetHeader?ID=106";
      options.PageOrientation = Wkhtmltopdf.NetCore.Options.Orientation.Landscape;

      _generatePdf.SetConvertOptions(options);
  }
  else
  {

  }

Doesn't work in linux

I have the exception after deploying in docker container(linux)
System.IO.IOException: Broken pipe at Wkhtmltopdf.NetCore.GeneratePdf.GetByteArrayViewInHtml[T](String ViewInHtml, T model) at Document.API.Services.QuoteDocument.QuoteDocumentService.GenerateQuoteConfirmationDocument(QuoteConfirmationViewModel model) in /src/Services/Document/Document.API/Services/QuoteDocument/QuoteDocumentService.cs:line 28 at Document.API.Controllers.QuoteDocumentController.GetQuoteConfirmationDocument() in /src/Services/Document/Document.API/Controllers/QuoteDocumentController.cs:line 80 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
IMG:
image

I guess that problem in Dockerfile (need to install extra packages)
I changed Dockerfile(from example):
`FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
RUN apt-get update -qq && apt-get -y install libgdiplus libc6-dev
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Services/Document/Document.API/Document.API.csproj", "Services/Document/Document.API/"]
COPY ["BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj", "BuildingBlocks/EventBus/IntegrationEventLogEF/"]
COPY ["BuildingBlocks/EventBus/EventBus/EventBus.csproj", "BuildingBlocks/EventBus/EventBus/"]
COPY ["BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj", "BuildingBlocks/EventBus/EventBusRabbitMQ/"]
COPY ["BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj", "BuildingBlocks/EventBus/EventBusServiceBus/"]
RUN dotnet restore "Services/Document/Document.API/Document.API.csproj"
COPY . .
WORKDIR "/src/Services/Document/Document.API"
RUN dotnet build "Document.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Document.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
RUN chmod 755 /app/Rotativa/Linux/wkhtmltopdf

ENTRYPOINT ["dotnet", "Document.API.dll"]`
IMG:
image

Now I cannot build the image:

image

Can somebody help me to solve the problem?

Error in generate header

if (success)
            {
                var options = new ConvertOptions
                {
                    HeaderHtml = "http://localhost:44321/header.html",
                    PageOrientation = Wkhtmltopdf.NetCore.Options.Orientation.Landscape
                };

                _generatePdf.SetConvertOptions(options);

                return await _generatePdf.GetPdf("FacturePdf.cshtml", data);
            }

Exception: Exit with code 1 due to network error: RemoteHostClosedError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.