#1 2015-11-25 08:40:17

DefendeRRR
Member
Registered: 2015-11-25
Posts: 1

Pdf made from a Jpeg GrayScale has a red background, instead of white

Hello!

I have a document in a JPEG file (grayscale 8bit). When I make a PDF of it I've got a terrible background, red instead of white.

That's what I do:

var
	page: TPdfPage;
	pdfImage: TPdfImage;
	jpeg: SynGdiPlus.TJpegImage;	
	pdfDoc: TPDFDocument;
begin
	pdfDoc := TPDFDocument.Create(false, 0, true, nil);		
	try
		pdfDoc.Info.CreationDate := Now;
		pdfDoc.DefaultPaperSize := psA4;		
	
		jpeg := SynGdiPlus.TJpegImage.Create;
		try
			jpeg.LoadFromFile(FileName);                
			pdfImage := TPdfImage.Create(APdfDocument, jpeg, true)
		finally
			jpeg.Free;
		end;
		
		page := APdfDocument.AddPage;
		APdfDocument.AddXObject(AName, pdfImage);
		APdfDocument.Canvas.DrawXObject(0, 0, page.PageWidth, page.PageHeight, AName);			
		pdfDoc.SaveToStream(AOutStream);
	finally
		pdfDoc.Free;
	end;
end;

Please help me. Whether this is a bug or I do something wrong?

Offline

#2 2016-02-16 13:41:43

svuk
Member
Registered: 2011-09-28
Posts: 3

Re: Pdf made from a Jpeg GrayScale has a red background, instead of white

DrawXObject goes from bottom of page to up. So must be:

APdfDocument.Canvas.DrawXObject(0, page.PageHeight, page.PageWidth, page.PageHeight, AName);

Offline

Board footer

Powered by FluxBB