Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DinkToPdf on linux server doesn't show images #165

Open
TropinAlexey opened this issue Aug 16, 2022 · 3 comments
Open

DinkToPdf on linux server doesn't show images #165

TropinAlexey opened this issue Aug 16, 2022 · 3 comments

Comments

@TropinAlexey
Copy link

TropinAlexey commented Aug 16, 2022

I have a .NET 6 Web API project with DinkToPdf which I use on macOS on my dev machine, and two servers on Linux Ubuntu 20.4 and Windows Server 2012. My API detects OS on which it runs and uses the corresponding library to convert HTML to PDF file on output.

My controller:

public class ClientDocController : BaseController
{
    private readonly IClientAppointmentDocumentService _clientAppointmentDocumentService;
    private readonly IConverter _htmlToPdfConverter;

    public ClientDocController(IClientAppointmentDocumentService clientAppointmentDocumentService, IConverter htmlToPdfConverter)
    {
        _clientAppointmentDocumentService = clientAppointmentDocumentService;
        _htmlToPdfConverter = htmlToPdfConverter;
    }
    [HttpGet("{documentId}/pdf/")]
    [RestApiAuthorize(AccountRolePermissions.VIEW_CLIENT_DOCUMENTS)]
    public async Task<IActionResult> GetPdfAsync([FromRoute] int documentId, bool uploadToClientPortal, int? templateId = null, 
        bool clientPrint = false, bool sendToClientEmail = false, CancellationToken cancellationToken = default)
    {
        try
        {
            var htmlDocument = templateId == null
                ? await _clientAppointmentDocumentService.GetDefaultHtmlDocumentAsync(documentId, clientPrint, cancellationToken)
                : await _clientAppointmentDocumentService.GetHtmlDocumentAsync(documentId, templateId, clientPrint, cancellationToken);

            var fileName = $"Document_{documentId}_{DateTime.Now:s}.pdf";
            var conversionSettings = PdfConfigurationDefaults.GetDefaultSettings(htmlDocument); //this get individual settings for each platform
            var pdf = _htmlToPdfConverter.Convert(conversionSettings);
            var result = File(pdf, MediaTypeNames.Application.Pdf, fileName);

            if (sendToClientEmail) await _clientAppointmentDocumentService.SendToClientByEmailAsync(new[] {result});
            if (!uploadToClientPortal) return result;

            var accessToken = Request.Headers["Authorization"].ToString();
            var response = await _clientAppointmentDocumentService.UploadToClientPortalAsync(documentId, result, accessToken);
            return Ok(response);
        }
        catch (Exception e)
        {
            return BadRequest(e.Message);
        }
    }
}

This works well on all machines, although on Linux server there are images not included in resulting PDF under tag <img src="https://..." />.

What I have checked:

  • This is not SSL problem because if I make this controller to output HTML then images are shown as expected
  • I have tried every setting (maybe not in all combinations) in conversionSettings without any success
  • Converting images into base64 string also didn't help. Images didn't shown
  • Different image types from other hosts, didn't help

Anybody have any ideas, what can I check further?

@abuksh
Copy link

abuksh commented Dec 5, 2022

I have the same problem. I'm trying to display an image from Azure Blob storage, and it won't render the image. It just shows a blank box.
Has anyone found a solution for this yet?

@TropinAlexey
Copy link
Author

Hi. Here one workaround, but not solution

@omarhaj007
Copy link

Has anyone found a solution for this yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants