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.

Thu Jan 12, 2023 12:46 pm

Im facing a problem where I cannot draw image into a pdf. I have attached the sample for testing and below is the code I used.
Im using spire pdf ver 8.1.8

Please advise

Code: Select all
 
foreach (string im in imageList)
{
       PdfSection section = pdf.Sections.Add();
       PdfPageBase page = pdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
       PdfImage pdfImage = PdfImage.FromFile(im);
       float widthFitRate = pdfImage.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
       float heightFitRate = pdfImage.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
       float fitRate = Math.Max(widthFitRate, heightFitRate);
       float fitWidth = pdfImage.PhysicalDimension.Width / fitRate;
       float fitHeight = pdfImage.PhysicalDimension.Height / fitRate;
       page.Canvas.DrawImage(pdfImage, 5, 5, fitWidth, fitHeight);
}
pdf.SaveToFile("result.pdf");

xiao0207
 
Posts: 45
Joined: Thu Dec 13, 2018 9:50 am

Fri Jan 13, 2023 7:55 am

Hi,

Thanks for your inquiry.
I tested your two images with your sample code, using the version you used and the latest version (9.1.0), I did not reproduce your issue, but the contents in your images flash and disappear when I open them, in addition, if the scale rate of the output pdf document is too high, the contents are almost invisible. I have attached the output document, you can have a look. I guess the issue is caused by your two images, you can find some other images and draw them to a pdf document. if your issue still exists after testing other images, please provide us with the following messages to help us investigate further, you can send them to us via email ([email protected]) or attach them here, thanks for your assistance.
1) your output document.
2) your test environment, such as OS info (E.g., Windows 10 64bit) and region setting (E.g., China, Chinese)

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Feb 03, 2023 7:37 am

Hi,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience? If your issue still exists, please provide us with the following messages.
1) your output document.
2) your test environment, such as OS info (E.g., Windows 10 64bit) and region setting (E.g., China, Chinese).

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF