Hello Timothy,
Thanks for contacting support.
TimothyBlue:
I want my header to have the logo on the left and words on the right centered with the logo. I cannot use the ImageStamp because it doesn’t work with SVG files so I am trying to use a table in the logo with the SVG in it but I get
Exception thrown: ‘System.ArgumentOutOfRangeException’ in mscorlib.dll
Additional information: StartIndex cannot be less than zero.
I have tried to add SVG image inside table and I was unable to observe the exception which you have mentioned. Though the image was not visible in the resultant PDF document after code was executed, so I have logged an issue as PDFNET-42748 in our issue tracking system with my sample output document.
Concerning to the issue which you have mentioned, we will appreciate if you can share a sample input document (if any) along with the SVG image, so that we can try to replicate the issue in our environment and address it accordingly.
TimothyBlue:
I am trying to add a logo to the header of a PDF. When I use images they always look bad no matter how I set up the size and quality. They are always pixelated
I have also tried to add JPG image in the PDF document through your code and I was unable to notice the bad pixel/quality issue (Please check the attached document). Please note that the image will look improper or bad if changing its height and width disturbs its aspect ratio. In order to maintain the pixel quality of the image you need to maintain its aspect ratio.
Please check following code snippet to change the height and width of the image so that its aspect ratio would remain same.
FileStream stream = new FileStream(dataDir + “sampleimage.jpg”, FileMode.Open);
System.Drawing.Image img = new Bitmap(stream);
img = ScaleImage(img, (int)pdfImageSection.PageInfo.Width, (int)pdfImageSection.PageInfo.Height);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
var image = new Aspose.Pdf.Image { ImageStream = ms };
public static System.Drawing.Image ScaleImage(System.Drawing.Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(newImage))
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
return newImage;
}
In case if you still face image quality issue, please share your sample input file(s), so that we can also try to test the scenario in our environment and address it accordingly.
Best Regards,