Using TPDFCanvas Directly

TeeChart FireMonkey (Windows,OSX,iOS & Android) for Embarcadero RAD Studio, Delphi and C++ Builder (XE5+)
Post Reply
BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

Using TPDFCanvas Directly

Post by BruceC » Mon Mar 21, 2016 9:00 am

I am not using any TeeChart component. But create a TPDFCanvas in code as follows:

Code: Select all

  PDF:=TPDFCanvas.Create;
  PDF.Document.Width:=842;
  PDF.Document.Height:=597;
  TTeeCanvas(PDF).Pen.Width:=ThickPen;
  PDF.DoHorizLine(42,800,100);  // 1st horizontal line
  TTeeCanvas(PDF).Pen.Width:=ThinPen;
  PDF.DoHorizLine(142,582,125);  // 2nd horizontal line
  TTeeCanvas(PDF).Pen.Width:=ThickPen;
  PDF.DoHorizLine(42,800,150);  // 3rd horizontal line
  TTeeCanvas(PDF).Pen.Width:=ThickPen;
  PDF.DoVertLine(42,100,400);   // 1st vertical line
  TTeeCanvas(PDF).Pen.Width:=ThinPen;
  PDF.DoVertLine(102,100,360);  // 2nd vertical ine
  TTeeCanvas(PDF).Pen.Width:=ThickPen;
  PDF.DoVertLine(142,100,400);  // 3rd vertical line
  PDF.Font.Family:='Helvetica';
  PDF.Font.Size:=14;
  PDF.Font.Color:=TAlphaColors.Black;
  PDF.TextAlign:=TA_LEFT;
...
  PDF.TextOut(350,20,'Anything');
...
 PDF.SaveToFile(S);
 PDF.DisposeOf;
This work perfectly running under windows but on Android and iOS it crashes with an access violation when calling the TextOut procedure. All of the other drawing of lines, etc. works fine.

I am using TeeChartVCL-2015.16. Is there something else that I should be initialising first?

BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

TeeSaveToPDFFile

Post by BruceC » Tue Mar 22, 2016 9:24 am

Text written using Canvas.TextOut is not shown on iOS, it shows fine on Android and Windows.

Also text shown as bold in the chart is not shown in the resultant PDF as bold.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Using TPDFCanvas Directly

Post by Yeray » Tue Mar 22, 2016 11:42 am

Hello Bruce,

Have you solved the problem with the text in PDF in Android?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

Re: Using TPDFCanvas Directly

Post by BruceC » Tue Mar 22, 2016 1:40 pm

I solved the first problem by programatically creating a TChart and writing to that in the OnAfterDraw event. With regard to the 2nd problem, no I haven't.
It works fine on Androidand WIndows but not iOS. No text is tisplayed at all. If I email the PDF generated to myself it is in the PDF and it views correctly on a WIndows PC. Must be something in the PDF that iOS does not like.

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Using TPDFCanvas Directly

Post by Yeray » Tue Mar 22, 2016 2:48 pm

Hi Bruce,

I've merged both topic because they seem to talk about the same, isn't it?
BruceC wrote:I solved the first problem by programatically creating a TChart and writing to that in the OnAfterDraw event.
Could you please expand on how did you solve that?
It may help us to find a solution for the problem on iOS.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

Re: Using TPDFCanvas Directly

Post by BruceC » Tue Mar 22, 2016 3:03 pm

Hi Yeray,

I believe that it is because the fonts are not embedded in the PDF. Is there a way of forcing this?

I can now confirm that the PDF generated also has no visible text on OSX too.

Bruce

BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

Re: Using TPDFCanvas Directly

Post by BruceC » Tue Mar 22, 2016 3:07 pm

Code:

Code: Select all

  Chart1:=TChart.Create(Self);
  with Chart1 do
  begin
    Parent:=Self;
    AllowPanning:=TPanningMode.pmNone;
    BackWall.Brush.Color:=TAlphaColors.White;
    BackWall.Color:=TAlphaColors.White;
    BackWall.Visible:=False;
    BottomWall.Visible:=False;
    LeftWall.Visible:=False;
    Legend.Visible:=False;
//    Title.Text.Strings[1]:='EKM-Mobile Weekly Report';
    Title.Visible:=False;
    AxisVisible:=False;
    BottomAxis.Automatic:=False;
    BottomAxis.AutomaticMaximum:=False;
    BottomAxis.AutomaticMinimum:=False;
    BottomAxis.Axis.Visible:=False;
    BottomAxis.Grid.Visible:=False;
    BottomAxis.Labels:=False;
    BottomAxis.LabelsFormat.Visible:=False;
    BottomAxis.Title.Visible:=False;
    BottomAxis.Visible:=False;
    Panning.MouseWheel:=pmwNone;
    Shadow.Visible:=False;
    View3DOptions.Orthogonal:=False;
    View3DWalls:=False;
    Zoom.Allow:=False;
    Zoom.Brush.Kind:=TBrushKind.None;
    Zoom.Pen.Visible:=False;
    BevelOuter:=bvNone;
    Color:=TAlphaColors.White;
    Enabled:=False;
    TabOrder:=0;
    EnableDragHighlight:=False;
    Size.PlatformDefault:=False;
    Size.Width:=842;
    Size.Height:=597;
    OnAfterDraw:=Chart1AfterDraw;
  end;

procedure TEditMonitoringForm.Chart1AfterDraw(Sender: TObject);
const
  ThickPen=1.0;
  ThinPen=0.5;
  RepTitle='WEEKLY MONITORING';
var
  I,J:Integer;
  Query:TFDQuery;
  WeekCommencingDate:TDate;
  Tots,Vals:array[1..11] of Single;
  FName,Comments:String;
  FontList:TStringList;
begin
  Inc(DrawCount);
//  Chart1.Canvas.Draw(700,15,Image1.Bitmap);
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoHorizLine(42,800,100);  // 1st horizontal line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoHorizLine(142,582,125);  // 2nd horizontal line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoHorizLine(42,800,150);  // 3rd horizontal line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoVertLine(42,100,400);   // 1st vertical line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoVertLine(102,100,360);  // 2nd vertical ine
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoVertLine(142,100,400);  // 3rd vertical line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoVertLine(182,125,400);  // 4th vertical line
  Chart1.Canvas.DoVertLine(222,125,400);  // 5th vertical line
  Chart1.Canvas.DoVertLine(262,125,400);  // 6th vertical line
  Chart1.Canvas.DoVertLine(302,125,400);  // 7th vertical line
  Chart1.Canvas.DoVertLine(342,125,400);  // 8th vertical line
  Chart1.Canvas.DoVertLine(382,125,400);  // 9th vertical line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoVertLine(422,100,400);  // 10th vertical line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoVertLine(462,125,360);  // 11th vertical line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoVertLine(502,100,360);  // 12th vertical line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoVertLine(542,125,360);  // 13th vertical line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoVertLine(582,100,360);  // 14th vertical line
  Chart1.Canvas.DoVertLine(800,100,360);  // 15th vertical line
  Chart1.Canvas.Pen.Width:=ThinPen;
  Chart1.Canvas.DoHorizLine(42,800,180);  // 4th horizontal line
  Chart1.Canvas.DoHorizLine(42,800,210);  // 5th horizontal line
  Chart1.Canvas.DoHorizLine(42,800,240);  // 6th horizontal line
  Chart1.Canvas.DoHorizLine(42,800,270);  // 7th horizontal line
  Chart1.Canvas.DoHorizLine(42,800,300);  // 8th horizontal line
  Chart1.Canvas.DoHorizLine(42,800,330);  // 9th horizontal line
  Chart1.Canvas.Pen.Width:=ThickPen;
  Chart1.Canvas.DoHorizLine(42,800,360);  // 10th horizontal line
  Chart1.Canvas.DoHorizLine(42,422,400);  // 11th horizontal line
  Chart1.Canvas.Font.Family:='Helvetica';
  Chart1.Canvas.Font.Size:=14;
  Chart1.Canvas.Font.Color:=TAlphaColors.Black;
  Chart1.Canvas.TextAlign:=TA_LEFT;
  Chart1.Canvas.Font.Style:=[TFontStyle.fsBold,TFontStyle.fsUnderline];
  Chart1.Canvas.TextOut(350,20,RepTitle);
  Chart1.Canvas.Pen.Width:=ThickPen;
//  Chart1.Canvas.DoHorizLine(((800-PDF.TextWidth(RepTitle)) div 2)+2,((800-PDF.TextWidth(RepTitle)) div 2)+
//    Chart1.Canvas.TextWidth(RepTitle)+2,17+PDF.TextHeight(RepTitle));  // Underline Title
  Chart1.Canvas.Font.Size:=11;
  Chart1.Canvas.Font.Style:=[TFontStyle.fsBold];
  Chart1.Canvas.TextOut(42,60,'Name:');
  Chart1.Canvas.TextOut(200,60,'Week commencing:');
  Chart1.Canvas.TextOut(500,60,'Weight at end of week:');
  Chart1.Canvas.TextOut(58,118,'Date');
  Chart1.Canvas.TextOut(111,118,'Day');
  Chart1.Canvas.TextOut(200,105,'Number of seizures of each type');
  Chart1.Canvas.TextOut(160,124,'1');
  Chart1.Canvas.TextOut(200,124,'2');
  Chart1.Canvas.TextOut(240,124,'3');
  Chart1.Canvas.TextOut(280,124,'4');
  Chart1.Canvas.TextOut(320,124,'5');
  Chart1.Canvas.TextOut(360,124,'6');
  Chart1.Canvas.TextOut(400,124,'7');
  Chart1.Canvas.TextOut(153,136,'Abs');
  Chart1.Canvas.TextOut(193,136,'Myo');
  Chart1.Canvas.TextOut(230,136,'Drop');
  Chart1.Canvas.TextOut(269,136,'Tonic');
  Chart1.Canvas.TextOut(313,136,'T/C');
  Chart1.Canvas.TextOut(348,136,'Focal');
  Chart1.Canvas.TextOut(388,136,'Other');
  Chart1.Canvas.TextOut(440,100,'Blood or');
  Chart1.Canvas.TextOut(429,111,'urine ketones');
  Chart1.Canvas.TextOut(526,100,'Blood');
  Chart1.Canvas.TextOut(520,111,'glucose');
  Chart1.Canvas.TextOut(434,130,'AM');
  Chart1.Canvas.TextOut(474,130,'PM');
  Chart1.Canvas.TextOut(514,130,'AM');
  Chart1.Canvas.TextOut(554,130,'PM');
  Chart1.Canvas.TextOut(620,104,'Comments on any illness or');
  Chart1.Canvas.TextOut(625,118,'changes to diet, activity or');
  Chart1.Canvas.TextOut(670,132,'<strong>medication</strong>',true);
  Chart1.Canvas.TextOut(90,373,'Total');
  Chart1.Canvas.Font.Style:=[];
  Chart1.Canvas.TextOut(111,157,'Sun');
  Chart1.Canvas.TextOut(111,187,'Mon');
  Chart1.Canvas.TextOut(111,217,'Tue');
  Chart1.Canvas.TextOut(111,247,'Wed');
  Chart1.Canvas.TextOut(111,277,'Thu');
  Chart1.Canvas.TextOut(111,307,'Fri');
  Chart1.Canvas.TextOut(111,337,'Sat');
  WeekCommencingDate:=IncDay(StartOfTheWeek(lblDate.TagFloat),-1);
  Query:=TFDQuery.Create(Nil);
  Query.Connection:=MainForm.FDConnection;
  for I:=1 to 11 do
    Tots[I]:=0;
  for I:=1 to 7 do
  begin
    Chart1.Canvas.TextOut(44,157+((I-1)*30),FormatDateTime('dd/mm/yyyy',IncDay(WeekCommencingDate,I-1)));
    Query.SQL.Text:='select * from MonitorDay where PatientID='+qPatients.FieldByName('ID').AsString+' and DayDate='+
      QuotedStr(FormatDateTime('YYYY-MM-DD',IncDay(WeekCommencingDate,I-1)));
    Query.Open;
    if Query.IsEmpty then
    begin
      Comments:='';
      for J:=1 to 11 do
        Vals[J]:=0;
    end else
    begin
      Comments:=Query.FieldByName('Comments').AsString;
      for J:=1 to 7 do
        Vals[J]:=Query.FieldByName('Seize'+IntToStr(J)).AsInteger;
      Vals[8]:=Query.FieldByName('KetonesAM').AsFloat;
      Vals[9]:=Query.FieldByName('KetonesPM').AsFloat;
      Vals[10]:=Query.FieldByName('GlucoseAM').AsFloat;
      Vals[11]:=Query.FieldByName('GlucosePM').AsFloat;
    end;
    for J:=1 to 7 do
    begin
      Tots[J]:=Tots[J]+Vals[J];
      Chart1.Canvas.TextOut(153+((J-1)*40),157+((I-1)*30),Format('%4d',[Round(Vals[J])]));
    end;
    for J:=8 to 11 do
    begin
      Chart1.Canvas.TextOut(155+((J-1)*40),157+((I-1)*30),Format('%3.1f',[Vals[J]]));
    end;
    if Comments<>'' then
      Chart1.Canvas.TextOut(584,157+((I-1)*30),Comments);
    Query.Close;
  end;
  for J:=1 to 7 do
    Chart1.Canvas.TextOut(153+((J-1)*40),373,Format('%4d',[Round(Tots[J])]));
  Query.DisposeOf;
  if DrawCount=1 then
  begin
    FName:=GetFullPathName('Weekly.pdf');
    if FileExists(FName) then
      DeleteFile(FName);
    TeeSaveToPDFFile(Chart1,FName,Round(Chart1.Width),Round(Chart1.Height));
//    DisplayPDFFile(FName);
    Chart1.Visible:=False;
  end;
end;

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Using TPDFCanvas Directly

Post by Yeray » Wed Mar 23, 2016 10:38 am

Hello,

I could reproduce the problem thanks to your code so I've added it to the public tracker:
http://bugs.teechart.net/show_bug.cgi?id=1477

Feel free to add your mail to the CC list to be automatically notified when an update arrives.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

BruceC
Newbie
Newbie
Posts: 19
Joined: Mon Nov 16, 2015 12:00 am

Re: Using TPDFCanvas Directly

Post by BruceC » Wed Mar 23, 2016 11:59 am

Thanks. I need to be able to get this working asap for a childrens charity organization. Is there any way I can force the fonts to be included in the current version?

Yeray
Site Admin
Site Admin
Posts: 9614
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Using TPDFCanvas Directly

Post by Yeray » Wed Mar 30, 2016 10:30 am

Hello Bruce,

I'm sorry but I'm afraid I can't tell you when this will be fixed.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply