logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ju1989  
#1 Posted : Thursday, June 7, 2018 12:30:17 AM(UTC)
ju1989

Rank: Member

Groups: Registered
Joined: 6/1/2016(UTC)
Posts: 28
Germany
Location: Hessen

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I have a PDF document which gets rendered very strange. I think it is a Problem of contrast and brightness.

I use the following Code to get the Image.



Code:

using (MemoryStream bitmapStream = new MemoryStream())
{
	lock (lockObject)
	{
		using (var bitmap = new Bitmap(targetWidth, targetHeight))
		{
			using (var g = Graphics.FromImage(bitmap))
			{
				g.FillRectangle(new SolidBrush(Color.White), 0, 0, targetWidth, targetHeight);
				using (var pdfBitmap = new PdfBitmap(targetWidth, targetHeight, true))
				{
					page.Render(pdfBitmap, 0, 0, targetWidth, targetHeight, PageRotate.Normal, RenderFlags.FPDF_ANNOT);
					g.DrawImageUnscaled(pdfBitmap.Image, 0, 0);
				}
			}
			bitmap.Save(bitmapStream, imageFormat);
			return bitmapStream.ToArray();
		}
	}
}


Attached is the PDF document document.pdf (894kb) downloaded 7 time(s)., the output image of Adobe Reader output_acrobat.png (1,035kb) downloaded 8 time(s). and the output of the Code above output_pdfium.png (680kb) downloaded 7 time(s)..

Do you have any ideas how to fix it?
Paul Rayman  
#2 Posted : Friday, June 8, 2018 7:20:29 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
The code below produce normal output image.
I do not know how you could get other one. Can you provide the full code?

Code:

            using (var doc = PdfDocument.Load(@"d:\0\4\document.pdf"))
            {
                using (var page = doc.Pages[0])
                {
                    int targetWidth = (int)(page.Width / 72.0f * 96.0f);
                    int targetHeight = (int)(page.Height / 72.0f * 96.0f);
                    using (var bitmap = new Bitmap(targetWidth, targetHeight))
                    {
                        using (var g = Graphics.FromImage(bitmap))
                        {
                            g.FillRectangle(new SolidBrush(Color.White), 0, 0, targetWidth, targetHeight);
                            using (var pdfBitmap = new PdfBitmap(targetWidth, targetHeight, true))
                            {
                                page.Render(pdfBitmap, 0, 0, targetWidth, targetHeight, PageRotate.Normal, RenderFlags.FPDF_ANNOT);
                                g.DrawImageUnscaled(pdfBitmap.Image, 0, 0);
                            }
                        }
                        bitmap.Save(@"d:\0\4\output.png", System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
            }
ju1989  
#3 Posted : Monday, June 11, 2018 3:51:51 AM(UTC)
ju1989

Rank: Member

Groups: Registered
Joined: 6/1/2016(UTC)
Posts: 28
Germany
Location: Hessen

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Sorry, my mistake. It is an additional applied DirectX shader.

-> closed
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.