Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Mar 17, 2020 3:46 pm

I have a bitmap created from a svg string which I then add to a pdf page and the save. However the resulting pdf image is just a black square.
The code sample is show below:

Code: Select all
var mySvg = SvgDocument.FromSvg<SvgDocument>(data);
            var bitmap = mySvg.Draw();

            bitmap.Save(@"C:\Data\barcode.bmp");
            PdfImage image = PdfImage.FromImage(bitmap);

            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            float width = image.Width * 0.75f;
            float height = image.Height * 0.75f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 60, width, height);

            doc.SaveToFile(@"C:\Data\barcode.pdf");


I am using the free spire pdf library and I have verified that barcode.bmp at line 3 has a visible image

fola.ext
 
Posts: 2
Joined: Tue Mar 17, 2020 3:36 pm

Wed Mar 18, 2020 2:31 am

Hello,

Thanks for your inquiry.
I tested the following code with Free Spire.PDF for .NET Version:6.2 and the latest commercial version Spire.PDF Pack(Hot Fix) Version:6.3.0, but the image of the generated PDF file is displayed normally. Attached is my output file.
Code: Select all
            PdfImage image = PdfImage.FromFile("barcode.bmp");
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();
            float width = image.Width * 0.75f;
            float height = image.Height * 0.75f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 60, width, height);
            doc.SaveToFile("barcode.pdf");

If you were using an old version, please try again with the latest version. If the issue still happens, to help us better look into it, please provide a runnable project that could reproduce your issue. You could send it to us([email protected]) via email.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Mar 26, 2020 9:01 am

Hello,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Mar 26, 2020 9:42 am

I was able to change the code that generated the barcode to produce an bitmap image rather than a svg string.
This seems to work and so you can consider the matter closed.

Thanks for checking back - hopefully from somewhere safe :D

fola.ext
 
Posts: 2
Joined: Tue Mar 17, 2020 3:36 pm

Thu Mar 26, 2020 10:07 am

Hello,

Thanks for your feedback and hope you are well.
If you need further assistance, please feel free to contact us.
We are always here to help.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF

cron