Git Product home page Git Product logo

Comments (7)

ThomasHoevel avatar ThomasHoevel commented on May 24, 2024 1

The "BASE64" notation does not currently work with the RTF Renderer. This is a different issue we are researching.

At the moment I'd recommend storing the image in a temporary file if you have to download it from the web.

from pdfsharp.

ThomasHoevel avatar ThomasHoevel commented on May 24, 2024

After a little code change, images in RTF work.
Code page 1252 is not UTF8, so remove this:

//public class MyEncodingProvider : EncodingProvider
//{
//    public override Encoding GetEncoding(int codepage)
//    {
//        if (codepage == 1252)
//        {
//            // Return your custom encoding object here
//            return Encoding.UTF8;
//        }
//        return null;
//    }

//    public override Encoding GetEncoding(string name)
//    {
//        // Implement this method if you want to support encoding names
//        return null;
//    }
//}

Register the encoder for code page 1252 (this should be included in the RTF Renderer soon, but with 6.0.0-preview-2 it must be called explicitly).

        //Encoding.RegisterProvider(new MyEncodingProvider());
        System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

from pdfsharp.

dnehl avatar dnehl commented on May 24, 2024

I tried to register the provider in the startup and also before I create the RTF document, but it still did not work. Now the image ins, not there and also not strange symbols.
Do I have to config the runtime env or the project file in a specific way?

from pdfsharp.

ThomasHoevel avatar ThomasHoevel commented on May 24, 2024

I do not know about any special requirements. We just use .NET 6 and I simply call RegisterProvider early in the code before creating the RTF Renderer.

The issue submission template worked with the changes shown above.

from pdfsharp.

dnehl avatar dnehl commented on May 24, 2024

Ok I found the issue, maybe you can help me to solve this as well.
I want to download the image first and add the byte array to the document.
When I create the pdf document everything, but the rtf document does not contain the image.

I am using the following code to download the image and create a byte array.

public static async Task<string> GetImage(string imageName, CancellationToken cancellationToken = default)
    {
        var httpClient = new HttpClient();
        var url = $"{BaseUrl}/nehl-it-icon.png";
        var response = await httpClient.GetAsync(
            url,
            cancellationToken);

        if (!response.IsSuccessStatusCode)
        {
            return string.Empty;
        }

        return LoadImageFromBytes(await response.Content.ReadAsByteArrayAsync(cancellationToken));
    }

    protected static string LoadImageFromBytes(byte[] cData)
    {
        return $"base64:{Convert.ToBase64String(cData)}";
    }

var imageFilePath = await GetImage("Generali.png");

var image = document.LastSection.Headers.Primary.AddImage(imageFilePath);

from pdfsharp.

dnehl avatar dnehl commented on May 24, 2024

Ok, thanks for the feedback!
Is there an open issue, where I can watch it?

from pdfsharp.

ThomasHoevel avatar ThomasHoevel commented on May 24, 2024

BASE64 support for RTF Renderer has been fixed.
Fix will be included with version 6.0.0-preview-3 coming soon (May or June 2023 or so).

from pdfsharp.

Related Issues (20)

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.