Coder Social home page Coder Social logo

changemakerstudios / gotenbergsharpapiclient Goto Github PK

View Code? Open in Web Editor NEW
102.0 10.0 16.0 2.09 MB

.NET C# Client for the Gotenberg API

License: Apache License 2.0

C# 38.42% HTML 1.42% CSS 0.16% Rich Text Format 60.00%
pdf pdf-converter csharp netstandard url-to-pdf html-to-pdf pdf-merge typed-clients fluent async

gotenbergsharpapiclient's People

Contributors

chrismo111 avatar jaben avatar naefp avatar raschmitt 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  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  avatar

gotenbergsharpapiclient's Issues

Breaking change in .NET 6 causes this client to throw exception because of Globalization issues

In .Net 6 it is know thrown exception if invariant culture is enabled, but the app is creating a specific culture.

E.g. see this:
https://docs.microsoft.com/en-us/dotnet/core/compatibility/globalization/6.0/culture-creation-invariant-mode

Below is a line from your code where a specific culture info is used. Maybe just set it to Cultureinfo.InvariantCulture?

var cultureInfo = CultureInfo.GetCultureInfo("en-US");

No emulatedMediaType option for v7

There is currently no emulatedMediaType=screen option.

This option renders page exactly what it looks like on web and not in print mode.

I will be happy to contribute to v7 branch if you need any help.

Dimensions.cs ToHttpContent() breaks numeric values due to unawareness of globalization

Used the API on a german Windows. Having this the output of ToString() of 8.3 will be 8,3 which breaks the request to Gotenberg with an unable to convert to float message.

Used this to fix the issue:

StringContent contentItem;
switch (value)
{
  case float f:
    contentItem = new StringContent(f.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
    break;
   case double d:
     contentItem = new StringContent(d.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
     break;
    case decimal c:
      contentItem = new StringContent(c.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
      break;
     case int i:
       contentItem = new StringContent(i.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
       break;
      case long l:
        contentItem = new StringContent(l.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
        break;
      case DateTime date:
        contentItem = new StringContent(date.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));
        break;
      default:
        contentItem = new StringContent(value.ToString());  
        break;
}

Add support for the `exportFormFields` form field

Hi,

I have a small feature suggestion:

Gotenberg 8.3.0 introduced the new exportFormFields form field as an option for its forms/libreoffice/convert end point.
It's also documented at https://gotenberg.dev/docs/routes#page-properties-libreoffice.

This option is especially useful when converting Word documents containing content controls as currently, these are automatically transformed into form fields - a transformation that's not always ideal.

Best regards,
Mario

An item with the same key has already been added. Key: Gotenberg-Webhook-Extra-Http-Headers

After updating to v2 it seems impossible to set multiple request headers to the webhook request.

usage:

reqBuilder.AddWebhook(hook =>
  {
      hook.SetUrl(gotenbergWebHookUrl, HttpMethod.Post)
          .SetErrorUrl(gotenbergErrorUrl, HttpMethod.Post)
          .AddRequestHeader("JobId", jobId)
          .AddRequestHeader("DocumentId", documentId)
          .AddRequestHeader("ContentViewType", Enum.GetName(contentViewType));
  })

exception:

System.ArgumentException: An item with the same key has already been added. Key: Gotenberg-Webhook-Extra-Http-Headers
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Gotenberg.Sharp.API.Client.Domain.Builders.Faceted.WebhookBuilder.AddRequestHeader(String name, IEnumerable`1 values)
   at Gotenberg.Sharp.API.Client.Domain.Builders.Faceted.WebhookBuilder.AddRequestHeader(String name, String value)

It seems like the method AddRequestHeader should either accept an IDictionary<string, string> / IDictionary<string, IEnumerable<string>> or handle multiple calls of the method correctly. I didnt deep dive into the differences between v1 and v2 and not into differences between Gotenberg v6 and v7, but on the first view it seems to be a bug in GotenbergSharpApiClient. Or am I wrong?

New version of Gotenberg ๐Ÿš€

Hello here ๐Ÿ‘‹

I've just released version 7.0.0 of Gotenberg ๐ŸŽ‰

A lot of minor changes, the best if you wish to update your C# client is to head to the new documentation.

Also, I've added your repository to the awesome list ๐Ÿ˜„ currently, I've marked it as only compatible with Gotenberg 6.x, but do not hesitate to open a PR when your client is compatible with version 7 ๐Ÿ‘

PS: if you have any questions, please ask them!

Convert single office file to pdf

As I understand you have to use GotenbergSharpClient.MergeOfficeDocsAsync for converting office files. But there is limitation that only allows 2 or more files to be converted. There is check for that:

foreach (var isValid in new[] { Count > 1, validItems.Value.Count > 1 })
if (!isValid) yield break;

Although Gotengberg docs shows that you could also use only one file.
Is there a reason for this limitation or should I use some other method?

Error handling

It looks like the client returns the result on error without any hints that is response is not 200 OK. Should it not throw an exception at least?

Parsing error on demensions parse float issue

I started using the example defined in the getting started and had instantly this error:

{"level":"error","msg":"strconv.ParseFloat: parsing "0,5": invalid syntax","op":"xhttp.htmlHandler: xhttp.chromePrinterOptions: resource.MarginArgs: resource.Resource.Float64Arg: xassert.Float64","time":"2020-03-04T09:27:32Z","trace":"RP4I2w1Xa684qWtwV7zeeRktGsi3j9I8"}

Compatibility with netcoreapp2.2

Should it be possible to reference this from a netcoreapp2.2 project?

Gotenberg.Sharp.Api.Client.csproj references Microsoft.Extensions.Http v3.0.0 which appears to prevent this situation

  • Gotenberg.Sharp.Api.Client.csproj
...
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
...

The change from v2.2.0 to v3.0.0 took place here

Container returns "Not Found" for all endpoints

I get 404 response for each gotenberg container endpoint. I tried every way to create it, each one returns the same - the string "Not Found" along with the HTTP 404 code. In the logs I get this:
image

I tried to use images, but neither works:

  • thecodingmachine/gotenberg:latest
  • thecodingmachine/gotenberg:7
  • gotenberg/gotenberg:gotenberg:latest
  • thecodingmachine/gotenberg:7

Using from within code also doesn't work. I have no ideas what else to do. I am asking for tips and correction of the log, because the present say nothing.

Release v1.1.0

@chrismo111 Okay to go ahead and release v1.1 with these fixes or do you have other things you want to put in there?

How to pass in Retry Option Settings when not using Dependency Injection (DI)?

I have the following Set-up

AppSettings

  "GotenbergSharpClient": {
    "ServiceUrl": "http://localhost:3000",
    "HealthCheckUrl": "http://localhost:3000/ping",
    "RetryPolicy": {
      "Enabled": true,
      "RetryCount": 4,
      "BackoffPower": 1.5,
      "LoggingEnabled": true
    }
  }
public void ConfigureServices(IServiceCollection services)
{
	.....
    services.AddOptions<GotenbergSharpClientOptions>()
	        .Bind(Configuration.GetSection(nameof(GotenbergSharpClient)));
    services.AddGotenbergSharpClient();
	.....    
}

Question 1:

I notice when I have this

var test = Configuration.GetSection(nameof(GotenbergSharpClient));

It is always null?

So not sure if the App settings is getting passed on to the GotenbergSharpClient or not?

Question 2:

When newing up the GotenbergSharpClient

_Instance = new GotenbergSharpClient(Settings.Current.PDFServer);

How does the Retry options get passed to it?

"RetryPolicy": {
      "Enabled": true,
      "RetryCount": 4,
      "BackoffPower": 1.5,
      "LoggingEnabled": true
    }

Not 100% sure when newing it up if the Retry Policies gets passed in to it?

I am thinking and hoping by looking at this

public static IAsyncPolicy<HttpResponseMessage> CreatePolicyFromSettings(IServiceProvider sp,
            HttpRequestMessage request)

it seems like the policy is created on HttpResponseMessage and it gets the settings from the service provider and since that
is provided in Startup.cs that the retry settings should be passed in regardless of how the Client is used?

Question 3:

How do I check to make sure that the retry settings are being passed into the Gotenberg Service correctly?

Question 4:

What is the best way to Unit test Gotenberg Server Errors which results in HttpResonse errors, to trigger the retry policy to kick in?

Thanks ๐Ÿ‘

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.