PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Adding background image renders grainy and choppy https://forum.pdfsharp.net/viewtopic.php?f=2&t=2614 |
Page 1 of 1 |
Author: | DaveRook [ Wed Oct 16, 2013 11:25 am ] | |||
Post subject: | Adding background image renders grainy and choppy | |||
I'm having some issues with creating PDF's, which I suspect is my own fault! I am trying to create a PDF with a background image. That is it. This is from a Project (Visual Studio 2012) although it's a website. public static string CreateTest() { try { string directory = @"C:\Users\Dave\Documents\Visual Studio 2012\Projects\Website\LifeCry\LifeCry\Content\Poster\"; PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); document.Options.NoCompression = true; document.Options.ColorMode = PdfColorMode.Cmyk; document.Version = 14; page.Size = PdfSharp.PageSize.A4; XImage xImagePosterBackground = XImage.FromFile(directory + "LifeCryPosterA4.jpg"); XGraphics graphics = XGraphics.FromPdfPage(page); graphics.DrawImage(xImagePosterBackground, new XPoint(0, 0)); string fileName = DateTime.Now.ToString("yyMMddhhmmss") + ".pdf"; document.Save(directory + fileName); return "../Content/Poster/" + fileName; } catch (System.Exception ex) { string s = ex.ToString(); System.Diagnostics.Debug.Assert(false, "beep beep, it failed!"); //TODO - impelement me (yeah, what ever) } } The issue is the page exports/renders incorrectly in anything but FireFox. This means, in IE, Chrome, PDX-XChange and PhotoShop, it renders incorrectly. See attached for screen shots of how it renders and how it should be. Here, I hope, you can see the issue. Is this a fault with my code? Any advice would be appreciated. Dave
|
Author: | Thomas Hoevel [ Wed Oct 16, 2013 12:36 pm ] |
Post subject: | Re: Adding background image renders grainy and choppy |
Hi! I presume your code will work under Windows XP. Here's a proposed change that may work with Windows NT 6.0 through 6.3 (aka Vista, 7, 8, 8.1): viewtopic.php?p=6963#p6963 |
Author: | DaveRook [ Wed Oct 16, 2013 2:34 pm ] |
Post subject: | Re: Adding background image renders grainy and choppy |
Thank you for the reply but the post cited has left me confused. The post suggests the following Quote: using (FileStream sourceFile = File.OpenRead(image.path)) But, as far as I know, Code: image doesn't have a path property.Either way, I can just create a string reference but, I don't see how I then pass this from a memory object into an XImage Code: graphics.DrawImage(xImagePosterBackground, new XPoint(0, 0));
|
Author: | Thomas Hoevel [ Wed Oct 16, 2013 2:51 pm ] |
Post subject: | Re: Adding background image renders grainy and choppy |
The change has to go to the XImage.cs file - and there is a path member (or _path). |
Author: | DaveRook [ Fri Oct 18, 2013 1:36 pm ] |
Post subject: | Re: Adding background image renders grainy and choppy |
I did what you suggested so the ximage.cs file now looks like Code: #if GDI memory = new MemoryStream(); if (!image.path.StartsWith("*")) { using (FileStream sourceFile = File.OpenRead(image.path)) { int count = 0; byte[] buffer = new byte[1024]; memory = new MemoryStream((int)sourceFile.Length); do { count = sourceFile.Read(buffer, 0, buffer.Length); memory.Write(buffer, 0, buffer.Length); } while (count > 0); } } else { memory = new MemoryStream(); image.gdiImage.Save(memory, ImageFormat.Jpeg); } //DR comment based upon pdfsharp suggestion image.gdiImage.Save(memory, ImageFormat.Jpeg); if ((int)memory.Length == 0) { Debug.Assert(false, "Internal error? JPEG image, but file not found!"); } #endif This made no difference I'm afraid to say. Thank you for your quick replies so far, it is appreciated. Do you know what I've done wrong? |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |