PDF pencil draw

I am using Delphi Alexandria and Macos Ventura for publising on IOS 16.4.1 .
In pdf pencil demo I click the "draw" button and sometimes I am able to draw with the pen and drawing stays. But sometimes the drawing vanished again directy even after having clicked on "Draw".

For testing I wrote a little app myself and came across the fact that DocViewer.FreeDraw.PencilEnabled := not DocViewer.FreeDraw.PencilEnabled dows not show me the drawing palette, nor am I able to draw on the surface.

Best regards

Mirko

Hi,

Did you attach the TTMSFMXNativePDFDocument ? We also have a small test sample that demonstrates the functionality. Did you try that out as well?

Good Morning Pieter,

yes I did.
I got a procedure loading the pdf:

procedure TPDFVIEWFORM.loadpdf(filename:String);
begin
  if filename <> '' then
  begin
    DocViewer.Free;
    DocViewer := TTMSFMXNativePDFDocumentViewer.Create(Self);
    DocViewer.Parent := PDFPANEL;
    DocViewer.Align := TAlignLayout.Client;
    DocViewer.Document := PDFD;
    PDFD.LoadFromFile(filename);
  end;
end;
procedure TPDFVIEWFORM.BTNPENClick(Sender: TObject);
begin
  DocViewer.FreeDraw.PencilEnabled := not DocViewer.FreeDraw.PencilEnabled;
end;

You see, its more or less the code you are using.

The PencilDraw Demo you provided shows the pen selection when I hit the "draw" button triggering the line DocViewer.FreeDraw.PencilEnabled := not DocViewer.FreeDraw.PencilEnabled;

But what is strange, sometimes I can draw on the pdf after having selected another color for example.
What never works is, that I just click "draw" and I can start drawing right away,
Also after having drawn a line I can no longer draw on the pdf.

I attached to screen capture videos to clearify what I mean.

Best regards

Mirko
RecordIt-1685087010.zip (2.2 MB)
RecordIt-1685087109.zip (3.3 MB)

Hi,

Are you drawing with the Apple Pencil or with the finger? The finger cannot be used to draw, only to navigate the PDF, zoom & scroll, and then annotations need to be added using the Pencil.

Definitely Apple Pen.
In the little menu on the lower right I even switched finger drawing off.
I always use the pen to draw in every app also in one note.

Hi,

The difference between Apple notes & the PDF is that we allow interaction with the PDF whilst drawing, maybe that's the issue. Can you apply the following code:

uses
  MacAPI.Helpers, MacAPI.ObjCRuntime, MacApi.ObjectiveC,
  iOSApi.Foundation, IOUtils, IOSApi.UIKit;

procedure TForm1.EnablePencil;
var
  I: Integer;
  sv: UIView;
begin
  docview.FreeDraw.PencilEnabled := not docview.FreeDraw.PencilEnabled;

  for I := 0 to docView.DocumentViewer.subviews.count - 1 do
  begin
    sv := TUIView.Wrap(docview.DocumentViewer.subviews.objectAtIndex(I));
    if sv.isKindOfClass(objc_getClass('UIScrollView')) then
      TUIScrollView.Wrap((sv as ILocalObject).GetObjectID).setScrollEnabled(not docview.FreeDraw.PencilEnabled);
  end;

end;

Sorry this is not working either.

Here is the complete code of the Demo as it is right now:

procedure TForm2.EnablePencil;
var
  I: Integer;
  sv: UIView;
begin
  docviewer.FreeDraw.PencilEnabled := not docviewer.FreeDraw.PencilEnabled;

  for I := 0 to docViewer.DocumentViewer.subviews.count - 1 do
  begin
    sv := TUIView.Wrap(docviewer.DocumentViewer.subviews.objectAtIndex(I));
    if sv.isKindOfClass(objc_getClass('UIScrollView')) then
      TUIScrollView.Wrap((sv as ILocalObject).GetObjectID).setScrollEnabled(not docviewer.FreeDraw.PencilEnabled);
  end;

end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  TMSFMXNativePDFDocument1.LoadFromURL(Edit1.Text);
end;


procedure TForm2.Button2Click(Sender: TObject);
begin
  EnablePencil;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  DocViewer := TTMSFMXNativePDFDocumentViewer.Create(Self);
  DocViewer.Parent := Panel1;
  DocViewer.Align := TAlignLayout.Client;
  DocViewer.Document := TMSFMXNativePDFDocument1;
  DocViewer.GetView.setContentScaleFactor(3.0);

  Button1Click(Self);
end;

Please check the attached video. When I choose a colour and the colour panel remains open I can directly write on the pdf. When the panel is closed writing is no longer possible and the colour seems to switch back to black though I chose something different as colour.

RecordIt-1685099624.zip (3.1 MB)

BUT I can draw with my fingers! I did not switch finger drawing on.

Hi,

Thanks for the additional info, I'll try to replicate this here using the above code. Stay tuned.

Hi Peter,

by the way is there andy detailed documentation, except for the demos you provide, concerning the new PDF components? I am wondering how to set the minimum, maxmum and inital zoom factor for the documents. I would like to have the first page fit to screen.

Rgds.

Mirko

The documentation is available here:

https://download.tmssoftware.com/doc/tmsicl/components/ttmsfmxnativepdfdocumentviewer/

It's currently not possible to adapt minimum/maximum zoom factor on the documents.

Thanks for the documentation.
But I see that there exists something like setting the initial scale.

    DocViewer := TTMSFMXNativePDFDocumentViewer.Create(Self);
    DocViewer.Parent := PDFPANEL;
    DocViewer.Align := TAlignLayout.Client;
    DocViewer.Document := PDFD;
    PDFD.LoadFromFile(filename);
    DocViewer.DocumentViewer.setScaleFactor(2.0); <- playing around with this
    DocViewer.DocumentViewer.setMinScaleFactor(2.0); <- playing around with this

DocumentViewer gives access to the underlying PDFView which can indeed be used to access native iOS calls, but they are not exposed directly as supported functionality in the component itself. Depending on the combination of certain properties it could be possible that these calls don't have the desired effect. But you can indeed experiment with those calls to achieve what you need until we actually implement this ourselves directly in the component.

Okay, setting the initial scale and the min scale works as follows:

  DocViewer.DocumentViewer.setMinScaleFactor(0.8);
  DocViewer.DocumentViewer.setScaleFactor(0.8);
  DocViewer.DocumentViewer.documentView.setContentScaleFactor(0.8);

With 0.8 I set the Initial Scale (Zoom) a bit smaller than the original size to fit to the screen.

1 Like

It kind of works somehow when I switch off "Scribble" in Settings -> Apple Pencil .
But I still can write with my fingers as well even though I switched it off.
But having Scribble deactivated I can directly write on the canvas (even multiple times) without having to click the "draw" button every time.

But the problem with the implementation in my app is still pending.
I got a button and onclick it executes:

DocViewer.FreeDraw.PencilEnabled := not DocViewer.FreeDraw.PencilEnabled;

But nothing happens. I cannot draw and it does not show the painting palette.
Do I have to activate pencil use in my app somehow, like in the manifest or so?

Rgds

Mirko

The pencil should automatically appear when you toggle this property, unless the SupportsPencil is returning False, can you check if SupportsPencil is returning false? If so, then your iOS version is not up to date, it needs to be at least iOS 16. If you have iOS 16 and the SupportsPencil is returning False, then perhaps you could force it to return true.

Okay gonna check this. But in your demo its working and I got Ios 16.4.1 so it should be working.
That I am still able to draw with my fingers seems to be based on that code.

procedure TForm2.EnablePencil;
var
  I: Integer;
  sv: UIView;
begin
  docviewer.FreeDraw.PencilEnabled := not docviewer.FreeDraw.PencilEnabled;

  for I := 0 to docViewer.DocumentViewer.subviews.count - 1 do
  begin
    sv := TUIView.Wrap(docviewer.DocumentViewer.subviews.objectAtIndex(I));
    if sv.isKindOfClass(objc_getClass('UIScrollView')) then
      TUIScrollView.Wrap((sv as ILocalObject).GetObjectID).setScrollEnabled(not docviewer.FreeDraw.PencilEnabled);
  end;

end;

Switching back to the single line docviewer.FreeDraw.PencilEnabled := not docviewer.FreeDraw.PencilEnabled works as intended. It was just scribble which i needed to switch off.

So do I conclude that it works now with scribble set to off and removing the additional iOS native code, or is there anything else not working as expected?

Now it is working also in my app. just needed to turn "Scribble" off. That's because it tries to interpret the written annotation and tries to convert it to typed characters.

Thanks for the info