Hello,
I need to create a 2 pages PDF document, first page must be landscape and second page must be portrait... on the first landscape page I have to write an horizontal JPG, and on the second portrait page I have to write a vertical JPG image.
the problem is that I can't write a 90° rotated jpg...
Document is created but second page is not rendered by Acroabt Reader and an error message is displayed opening the PDF (a problem occours on this page, page shoud not be displayed properly, contact the author of the PDF document to fix the problem).
This is the piece of code I'm using:
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
Image: TMemoryStream;
jpegDecompressor: tjhandle;
jpegWidth: cint;
jpegHeight: cint;
jpegSubsamp: cint;
jpegColorspace: cint;
begin
Image := TMemoryStream.Create;
FDocument := TPDFDocument.Create(Nil);
FDocument.Infos.Title := Application.Title;
FDocument.Infos.Author := 'TEST';
FDocument.Infos.Producer := 'TEST';
FDocument.Infos.ApplicationName := ApplicationName;
FDocument.Infos.CreationDate := Now;
FDocument.Options := [poPageOriginAtTop{, poCompressImages}];
FDocument.StartDocument;
FSection := FDocument.Sections.AddSection; // we always need at least one section
FPage := FDocument.Pages.AddPage;
FPage.PaperType := ptA4;
FPage.UnitOfMeasure := uomMillimeters;
FPage.Orientation := ppoLandscape;
FSection.AddPage(FPage);
Image.LoadFromFile('100_6625.JPG');
jpegDecompressor := tjInitDecompress();
tjDecompressHeader3(jpegDecompressor, Image.Memory, Image.Size, @jpegWidth, @jpegHeight, @jpegSubsamp, @jpegColorspace);
tjDestroy(jpegDecompressor);
i := FDocument.Images.AddJPEGStream(Image, jpegWidth, jpegHeight);
FPage.DrawImage(10, 200, 277.0, 190.0, i);
FPage := FDocument.Pages.AddPage;
FPage.PaperType := ptA4;
FPage.UnitOfMeasure := uomMillimeters;
FPage.Orientation := ppoPortrait;
FSection.AddPage(FPage);
Image.Clear;
Image.LoadFromFile('100_6626.JPG');
jpegDecompressor := tjInitDecompress();
tjDecompressHeader3(jpegDecompressor, Image.Memory, Image.Size, @jpegWidth, @jpegHeight, @jpegSubsamp, @jpegColorspace);
tjDestroy(jpegDecompressor);
i := FDocument.Images.AddJPEGStream(Image, jpegWidth, jpegHeight);
FPage.DrawImage(10, 287, 190.0, 277.0, i, 90); // <------ 90° rotation generates a wrong PDF file
FDocument.SaveToFile('test.pdf');
Image.Free;
Application.Terminate;
end;