Recent

Author Topic: PDF on a LAZ Form (Working Prototype)  (Read 12301 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
PDF on a LAZ Form (Working Prototype)
« on: February 15, 2017, 09:13:30 pm »
Okay... I completely figured this out on my own.

I have a working prototype of a PDF on a LAZ form using ActiveX (dll) and the LazActiveX control
as per this web page.... http://wiki.lazarus.freepascal.org/LazActiveX

Sorry... windows version only.

The hardest part was figuring out what declarations and methods to use from the library generated unit.

It works so far.
However, in the dev environment I get an Assembler error when I close the app.
But, running the compiled exe I don't see the error.

Here is the main unit code... (the generated library unit not shown)
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, activexcontainer, Forms, Controls, Graphics,
  9.   Dialogs, StdCtrls, AcroPDFLib_1_0_TLB;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ActiveXContainer1: TActiveXContainer;
  17.     Button1: TButton;
  18.     Edit1: TEdit;
  19.     Label1: TLabel;
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.   private
  23.     { private declarations }
  24.   public
  25.     { public declarations }
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.   AcroPDFX: IAcroAXDocShim;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. var
  40.    fn: WideString;
  41. begin
  42.   //fn := UTF8Decode('file:///'+StringReplace(FileNameEdit1.FileName, '\', '/', [rfReplaceAll]));
  43.   fn:= UTF8Decode(Edit1.Text);
  44.   AcroPDFX.LoadFile(fn);
  45.   AcroPDFX.setShowToolbar(True);
  46. end;
  47.  
  48. procedure TForm1.FormCreate(Sender: TObject);
  49. begin
  50.   AcroPDFX:=CoAcroPDF.Create;
  51.   ActiveXContainer1.ComServer:=AcroPDFX;
  52.   ActiveXContainer1.Active:=true;
  53. end;
  54.  
  55. end.
  56.  
  57.  

« Last Edit: February 15, 2017, 10:02:56 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #1 on: February 15, 2017, 09:20:43 pm »
One question I have...

Is how would I distribute this?
And or embed the DLL with it so I don't have DLL issues laster down the road??

Will I be able to embed DLL in the internal resource RES file?
« Last Edit: February 15, 2017, 09:33:42 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: PDF on a LAZ Form (Working Prototype)
« Reply #2 on: February 15, 2017, 10:17:53 pm »
You'll have to force your users to install Adobe Reader.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #3 on: February 15, 2017, 10:20:47 pm »
Yeah, that's what I thought.

Is there a way to embed the PDF as a RES..
or at least include it in my installation and link to my App dynamically?

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: PDF on a LAZ Form (Working Prototype)
« Reply #4 on: February 15, 2017, 10:33:24 pm »
check for mupdf on this forum ... mupdf + bgrabitmat works great
Speak postscript or die!
Translate to pdf and live!

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #5 on: February 15, 2017, 10:36:49 pm »
Already did... I believe you need a license to distribute commercially.
Money??

Plus, mine is working and I don't have to convert to all images.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Blestan

  • Sr. Member
  • ****
  • Posts: 461
Re: PDF on a LAZ Form (Working Prototype)
« Reply #6 on: February 15, 2017, 10:43:12 pm »
mudf is gpl..and made by the guys behind gostscript . and btw ater all everything is converted to image before draw on screen:))) not to mention that activex is ugly and old ... and not cross platform.. your choice
Speak postscript or die!
Translate to pdf and live!

jacmoe

  • Full Member
  • ***
  • Posts: 249
    • Jacmoe's Cyber SoapBox
Re: PDF on a LAZ Form (Working Prototype)
« Reply #7 on: February 15, 2017, 10:47:14 pm »
Quote
MuPDF is free software: you can redistribute it and/or modify it under the terms of the Affero GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

MuPDF is Copyright 2006-2015 Artifex Software, Inc.

For commercial licensing please contact sales@artifex.com.

That is a typical dual license: GPL - AGPL even - without any exception, and a commercial option.
« Last Edit: February 15, 2017, 10:49:05 pm by jacmoe »
more signal - less noise

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #8 on: February 15, 2017, 10:50:47 pm »
mudf is gpl..and made by the guys behind gostscript . and btw ater all everything is converted to image before draw on screen:))) not to mention that activex is ugly and old ... and not cross platform.. your choice

Well, not entirely true... Real PDF's are formatted docs. In the view-port you can select actual text and copy and paste. Even fonts are embedded in the PDF as an option.

And... yes, ActiveX may be old technology. But using DLL's is not.
It just to bad that there isn't a "real" PDF viewer for LAZ yet.

Since I am only targeting windows... the best Adobe Reader DLL is what I have that delivers real PDF's.

Not saying the mnuPDF is bad, but saving a huge 15 page PDF as all images would add a lot of overhead to my install.

I may get around to actually trying the mnPDf, but based on what I read, I am trying this first.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #9 on: February 15, 2017, 10:59:11 pm »
Doing a TEST...
I am embedding the PDF as a RES

However, I am getting an error....
Incompatible type for arg no1: Got "TResourceStream", expected "WideString"

Here is my code
Not exactly sure how I can convert the RS as a widestring

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   //fn: WideString;
  4.   RS: TResourceStream;
  5. begin
  6.   //fn:= UTF8Decode(Edit1.Text);
  7.   //AcroPDFX.LoadFile(fn);
  8.   //AcroPDFX.setShowToolbar(True);
  9.  
  10.   //load from resource
  11.     RS := TResourceStream.Create(HInstance, 'SHOWPDFINLAZ', RT_RCDATA);
  12.   try
  13.     //load from resource
  14.     AcroPDFX.LoadFile(RS);
  15.  
  16.   finally
  17.     RS.Free;
  18.   end;
  19.  
  20. end;  
  21.  

.
This is the line that is generating the error.
Code: Pascal  [Select][+][-]
  1.  AcroPDFX.LoadFile(RS);
  2.  

I usually use "LoadFromResource" into a control.
But, since the PDF dll is wrapped in an ActiveX control, I don't have that method available to me.

Is this even possible to load the RES (PDF file) into the ActX?
« Last Edit: February 15, 2017, 11:14:02 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: PDF on a LAZ Form (Working Prototype)
« Reply #10 on: February 16, 2017, 12:12:24 pm »
I have a working prototype of a PDF on a LAZ form using ActiveX (dll) and the LazActiveX control
as per this web page.... http://wiki.lazarus.freepascal.org/LazActiveX

Sorry... windows version only.

I have on good authority (and actual working code) that soon there will be a fully implemented PDF viewer component 100% implemented in Object Pascal. No 3rd party code or DLL's required. Obviously it's all cross-platform too. This was not implemented by me, but the author was kind enough to share his early work with me in private. I've thrown all kinds of PDF's at it, and it rendered them very well.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #11 on: February 16, 2017, 01:49:20 pm »
That's great!!!
When will it be made public?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: PDF on a LAZ Form (Working Prototype)
« Reply #12 on: February 16, 2017, 02:42:34 pm »
It's not my project, so I don't know the details. Better ask the author, José Mejuto (aka joshyfun).
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: PDF on a LAZ Form (Working Prototype)
« Reply #13 on: February 16, 2017, 04:34:30 pm »
I AM STILL HAVING A 'RES' ISSUE

Trying to get this to work with my PDF embedded as a RES.

I was getting this error...
Incompatible type for arg no1: Got "TResourceStream", expected "WideString"

I was able to at least stop the error message, but now the PDF doesn't load at all.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.     RS: TResourceStream;
  4. begin
  5.     //load from resource
  6.     RS := TResourceStream.Create(HInstance, 'SHOWPDFINLAZ', RT_RCDATA);
  7.    try
  8.     //load from resource
  9.     AcroPDFX.LoadFile(WideString(RS));
  10.  
  11.   finally
  12.     RS.Free;
  13.   end;
  14.  
  15. end;
  16.  

Any help would be appreciated
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: PDF on a LAZ Form (Working Prototype)
« Reply #14 on: February 16, 2017, 11:45:02 pm »
Code: Pascal  [Select][+][-]
  1. ...WideString(RS)...

You can't do a explicit conversion of stream class instance to filename!

If Adobe PDF ActiveX component doesn't support loading from a stream, then you need to save resource stream to a temporary file and then load it in ActiveX component.

 

TinyPortal © 2005-2018