#1 2014-10-22 01:13:33

serginho99
Member
From: Brasil/PR
Registered: 2014-08-10
Posts: 4

position (rotate) the JPG always in Horizontal

Hello,

I would like to position (rotate) the JPG always in Horizontal (with choice), I would like to know the code?

prong the 300dpi JPG always, if it is 100 dpi, 300 dpi to increase.

Offline

#2 2014-10-22 06:59:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: position (rotate) the JPG always in Horizontal

Using which unit/class?

TPdfCanvas, TPdfDocumentGDI, mORMotReport?

Offline

#3 2014-10-25 12:59:42

serginho99
Member
From: Brasil/PR
Registered: 2014-08-10
Posts: 4

Re: position (rotate) the JPG always in Horizontal

hi, below code used.

 

  pdfDoc   :TPdfDocument;
  pdfpage  :TPdfpage;
  JpegImage:TJpegImage;
  pdfImage :TPdfImage;

//=======
    pdfDoc                      := TPdfDocument.Create;
    pdfDoc.Info.Author     := 'Sergio';
    pdfDoc.Info.Creator    := 'Brazil';

    pdfDoc.NewDoc;

    for i:=0 to frmPdf.listview1.items.count-1 do
    begin
           JpegImage := TJpegImage.Create;
           JpegImage.LoadFromFile(caminhoJPG);

           pdfpage.PageWidth := Round(JpegImage.Width * 0.24001);  // for image 300dpi
           pdfpage.PageHeight:= Round(JpegImage.Height * 0.24001);
           pdfImage := TPdfImage.Create(pdfDoc, JpegImage,true);
           pdfDoc.AddXObject('image'+ inttostr(contador+1), pdfimage);
           pdfDoc.Canvas.DrawXObject(0,0,pdfpage.PageWidth,pdfpage.PageHeight,'image'+inttostr(contador+1));
           JpegImage.Free;
   end;
   pdfDoc.SaveToFile(caminhoSalva+'\'+ copiaNome + '.pdf');
   pdfDoc.Free;

Last edited by serginho99 (2014-10-25 13:03:12)

Offline

#4 2014-10-27 15:43:16

serginho99
Member
From: Brasil/PR
Registered: 2014-08-10
Posts: 4

Re: position (rotate) the JPG always in Horizontal

can someone help?

Offline

#5 2014-10-27 15:57:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: position (rotate) the JPG always in Horizontal

Take a look at DrawXObject:

procedure TPdfCanvas.DrawXObject(X, Y, AWidth, AHeight: Single;
    const AXObjectName: PDFString);
begin
  DrawXObjectPrepare(AXObjectName);
  GSave;
  ConcatToCTM(AWidth, 0, 0, AHeight, X, Y);
  ExecuteXObject(AXObjectName);
  GRestore;
end;

I guess you can change the rotation by changing the ConcatToCTM default parameters.
See http://stackoverflow.com/a/19909409/458259

If you find out how to rotate the image.
Perhaps http://stackoverflow.com/a/17288854/458259 may help, as well as Section 4.2.1, “Coordinate Spaces” of the PDF reference manual.

This is how we do text rotation in TPdfEnum.TextOut:

      a := font.spec.angle*(PI/180);
      acos := cos(a);
      asin := sin(a);
      PosX := 0;
      PosY := 0;
      Canvas.SetTextMatrix(acos, asin, -asin, acos,
        Canvas.I2X(Posi.X-Round(W*acos+H*asin)),
        Canvas.I2Y(Posi.Y-Round(H*acos-W*asin)));

You can use the same kind of parameters.

Offline

Board footer

Powered by FluxBB