Recent

Author Topic: [SOLVED] fpPDF -> add existing PDF ?  (Read 7928 times)

scons

  • Full Member
  • ***
  • Posts: 141
[SOLVED] fpPDF -> add existing PDF ?
« on: August 15, 2018, 10:09:08 am »
Hi all,

I am playing around with fpPDF, so far, so good.

Now I have a question : In most pdf's text is selectable. Is it possible to add an existing pdf in fpPDF and keep this functionality ? (add existing pdf in its original state)

I was able to convert an existing pdf to a PNG and add it but then it is (of course) not possible anymore to select something from the original pdf.

So if someone can point me in the right direction, would be appreciated.

Thanks.
« Last Edit: August 26, 2018, 10:20:58 am by scons »
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: fpPDF -> add existing PDF ?
« Reply #1 on: August 15, 2018, 03:59:15 pm »
I was able to convert an existing pdf to a PNG and add it but then it is (of course) not possible anymore to select something from the original pdf.

Sorry for the off-topic: what tool did you use to convert PDF into PNG?

scons

  • Full Member
  • ***
  • Posts: 141
Re: fpPDF -> add existing PDF ?
« Reply #2 on: August 15, 2018, 08:32:29 pm »
No Problem

I started with ImageMagick, then PascalMagick, but ran into a few missing parts that would make it more convenient, maybe I will go back to this route once the package gets an upgrade. But after upgrading to a later version of GhostScript it ran noticably slower for some reason, which was a little strange.

Then I played around with MuPDF.

The last one was/is Xpdf. For now I will keep Xpdf.

It is an ongoing process, I try spend some (rare) free time on this subject.
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

scons

  • Full Member
  • ***
  • Posts: 141
Re: fpPDF -> add existing PDF ?
« Reply #3 on: August 17, 2018, 03:26:22 pm »
Ok I have 2 follow-up questions:

  • I'm trying to change the format to a custom format, how do I have to add the H and W ? (code below)
  • If I want to add more "default paper size, lets say sizes A0 -> A4, I add them to the source file (ptA0, ptA1,  + sizes) and then ... ?

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   Classes,
  7.   fpPDF { you can add units after this };
  8.  
  9. var
  10.   PDF: TPDFDocument;
  11.   page: TPDFPage;
  12.   section: TPDFSection;
  13.   IDX: Integer;
  14.   W, H: Integer;
  15.  
  16. begin
  17.   PDF := TPDFDocument.Create(nil);
  18.   try
  19.     PDF.StartDocument;
  20.     section := PDF.Sections.AddSection;
  21.     page := PDF.Pages.AddPage;
  22.     page.Orientation:= ppoLandscape;
  23.     page.Orientation:= ppoLandscape;
  24.     page.UnitOfMeasure:= uomPixels;
  25.     page.PaperType:= ptCustom;
  26.  
  27.     //  define here width (W) and height (H) ?
  28.     //  page.Paper.H:= a value; -> doesn't seem to work ?
  29.  
  30.     section.AddPage(page);
  31.  
  32.     IDX := PDF.Images.AddFromFile('C:\Temp\test.png');
  33.     W := PDF.Images[IDX].Width;
  34.     H := PDF.Images[IDX].Height;
  35.     page.DrawImageRawSize(0, 0, W, H, IDX);
  36.  
  37.     PDF.SaveToFile('C:\Temp\test.pdf');
  38.   finally
  39.     PDF.Free;
  40.   end;
  41. end.
  42.  

Thanks
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: fpPDF -> add existing PDF ?
« Reply #4 on: August 19, 2018, 07:24:34 pm »
Saw this on the fpPDF site.
http://www.fpdf.org/en/doc/__construct.htm

You set custom height and width by sending an array. Example is at the bottom.

Quote
__construct
__construct([string orientation [, string unit [, mixed size]]])
Description
This is the class constructor. It allows to set up the page size, the orientation and the unit of measure used in all methods (except for font sizes).
Parameters

orientation
    Default page orientation. Possible values are (case insensitive):

        P or Portrait
        L or Landscape

    Default value is P.
unit
    User unit. Possible values are:

        pt: point
        mm: millimeter
        cm: centimeter
        in: inch

    A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.

    Default value is mm.
size
    The size used for pages. It can be either one of the following values (case insensitive):

        A3
        A4
        A5
        Letter
        Legal

    or an array containing the width and the height (expressed in the unit given by unit).

    Default value is A4.

Example
Example with a custom 100x150 mm page size:

$pdf = new FPDF('P','mm',array(100,150));



Rick
« Last Edit: August 19, 2018, 07:27:31 pm by rick2691 »
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: fpPDF -> add existing PDF ?
« Reply #5 on: August 19, 2018, 07:32:23 pm »
I just realized that the above might be a different animal. It is fPDF, not fpPDF. It might work the same though. People usually try unify commands.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

scons

  • Full Member
  • ***
  • Posts: 141
Re: fpPDF -> add existing PDF ?
« Reply #6 on: August 25, 2018, 08:12:34 am »
Thanks for your input Rick, appreciated.

Yes it is the fcl-pdf included in Lazarus installation I am talking about, sorry if it was not clear.

But I would like to know when I do this:

Code: Pascal  [Select][+][-]
  1. ...
  2.     section := PDF.Sections.AddSection;
  3.     page := PDF.Pages.AddPage;
  4.  
  5.     Paper.H:=1000;
  6.     Paper.W:=1500;
  7.     Paper.Printable.T:=10;
  8.     Paper.Printable.L:=10;
  9.     Paper.Printable.R:=1490;
  10.     Paper.Printable.B:=990;
  11.  
  12.     page.Orientation:= ppoLandscape; // <- try to comment this out
  13.     page.PaperType:= ptCustom;
  14.     page.UnitOfMeasure:= uomMillimeters;  // <- uomPixels is no difference
  15.  
  16.     section.AddPage(page);
  17. ...
  18.  

It keeps returning an A4 size. Must be doing something wrong.
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: fpPDF -> add existing PDF ?
« Reply #7 on: August 25, 2018, 04:39:54 pm »
It keeps returning an A4 size. Must be doing something wrong.

I don't know, but I just saw this in the source code:
Code: Pascal  [Select][+][-]
  1. //fcl-pdf\src\fppdf.pp
  2.   TPDFPage = Class(TPDFDocumentObject)
  3. ...
  4.     // Set this if you want custom paper size. You must set this before setting PaperType = ptCustom.
  5.     Property Paper : TPDFPaper Read FPaper Write FPaper;

Quote
    // Set this if you want custom paper size. You must set this before setting PaperType = ptCustom

scons

  • Full Member
  • ***
  • Posts: 141
Re: [SOLVED] fpPDF -> add existing PDF ?
« Reply #8 on: August 26, 2018, 10:21:56 am »
Thanks mr engkin, your pointer solved my issue.
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

 

TinyPortal © 2005-2018