Comments (7)
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.
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.
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.
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.
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.
Ok, thanks for the feedback!
Is there an open issue, where I can watch it?
from pdfsharp.
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)
- Initial findings HOT 2
- XGraphics.DrawMatrixCode ignores XBrush parameter HOT 1
- Issues with content-related classes
- PDFsharp fails to open pdfs. HOT 1
- Image has no valid type error HOT 1
- MigraDoc: AddImage nolonger supports usage of memorystream HOT 7
- MAUI Android: "Specified method is not supported." exception in PdfReader.Open() HOT 2
- Ximage FromStream Exception HOT 1
- Suggestion: PdfDocumentRenderer.RenderDocument() should support cancel/stop HOT 7
- Html renderer HOT 1
- Regression: No appropriate font found for family name "Segoe UI". HOT 4
- Unexpected EOF error while reading PDF using PdfSharp HOT 1
- Null check throws before generating DataMatrix Image HOT 4
- Efficiently Merging multiple PDFs HOT 1
- *** Please use the Support forum to ask Support questions ***
- Font Load/Display Issues HOT 9
- CodeOmr not usable caused by a specific hack
- Getting Outlines.Count throws TargetInvocationException and Inner Exception: Destination Array expected. HOT 3
- Read real font from AcroForm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfsharp.