Recent

Author Topic: "Free JPDF Pascal" STABLE VERSION 1.0 - Reports in PDF - Desktop, Mobile and CGI  (Read 66872 times)

kitsaros

  • New Member
  • *
  • Posts: 27
It's me again .
I have managed to modify this library in order to "accept" CP1250 CP1251 CP1252 CP1253 codepages .
I have made the "Greek" version of the demo.
The bad news are that sumatra pdf does not recognize the Greek characters [and i dont know why] .
If you use the CP1250 codepage recognizes the polish characters ĄąŻżŹźŚśĘęĆćŃńÓóŁł .
On PDF-XChange Viewer / fox reader and on CoolPDFReader all works fine.
I am based on this trick : http://www.tv.com.pl/stepbystep/pdfinclude/

The modded library can be found here :
https://onedrive.live.com/redir?resid=1024B4FF999DA333!152&authkey=!AITy0grJAhtlPy4&ithint=file%2c.zip 

You are free to mod this lib as well.

Let me know what fdo you think about this "hack"

kpeters58

  • Sr. Member
  • ****
  • Posts: 267

Noticed the bug below - see last line of posted code marked with my initials ...

Code: [Select]
procedure TJPFpdf.Writer(const vHeight: Double; vText: String);
var
  vfamily: TPDFFontFamily;
  vstyle:  TPDFFontStyle;
  vw:      Extended;
  vwmax:   Extended;
  vs:      String;
  vnb:     Integer;
  vnl:     Integer;
  vl:      Integer;
  vj:      Integer;
  vi:      Integer;
  vsep:    Integer;
  vc:      Char;
  fUTF8:   Boolean;

begin
  fUTF8 := False;
  if (pUTF8) then
  begin
    vText := UTF8ToUTF16(vText);
    SetUTF8(False);
    fUTF8 := True;
  end;
  //Output text in flowing mode
  vfamily := Self.cFontFamily;
  vstyle  := Self.cFontStyle;
  if (vfamily in [ffCourier, ffSymbol, ffZapfdingbats]) then
    vstyle := fsNormal;
  //
  vw    := Self.dw - Self.rMargin - Self.cpX;
  vwmax := (vw - 2 * Self.cMargin) * 1000 / Self.cFontSize;
  vs    := StringReplace(vText, #13, '', [rfReplaceAll]);
  vnb   := Length(vs);
  vsep  := -1;
  vi    := 1;// KPKPKP  was 0 - which lead to range error (when range checking was on)   
Lazarus 2.0.4/FPC 3.0.4/Win 64

NumberCruncher

  • Newbie
  • Posts: 1
Hi, if you insert multiple (different) pictures into the same page, all pictures will be the same. A possible way to fix it:

Code: Pascal  [Select][+][-]
  1. procedure TJPFpdf.Image(vFile: string; vX: double; vY: double;
  2.   vWidth: double; vHeight: double);
  3. var
  4.   i, imgcounter: integer;
  5.   img: TJPImageInfo;
  6.   flag: boolean;
  7. begin
  8.   imgcounter:=0;
  9.   //Put an image on the page
  10.   flag := False;
  11.   if (Length(Self.pImages) > 0) then
  12.     for i := 0 to Length(Self.pImages) - 1 do
  13.     begin
  14.       if (Self.pImages[i].filePath = vFile) then
  15.       begin
  16.         flag := True;
  17.         img := Self.pImages[i];
  18.         imgcounter:=i+1;
  19.         break;
  20.       end;
  21.     end;
  22.   if not (flag) then
  23.   begin
  24.     //First use of image, get info
  25.     SetLength(Self.pImages, Length(Self.pImages) + 1);
  26.     Self.pImages[Length(Self.pImages) - 1].imgSource := TMemoryStream.Create;
  27.     Self.pImages[Length(Self.pImages) - 1] := GetInfoImage(vFile);
  28.     Self.pImages[Length(Self.pImages) - 1].n := Length(Self.pImages);
  29.     Self.pImages[Length(Self.pImages) - 1].filePath := vFile;
  30.     img := Self.pImages[Length(Self.pImages) - 1];
  31.     imgcounter:=Length(Self.pImages);
  32.   end
  33.   else
  34.   //Automatic width or height calculus
  35.   if (vWidth = 0) then
  36.     vWidth := StrToFloat(FloatToStrF((vHeight * img.w / img.h), ffNumber,
  37.       14, 2, TPDFFormatSetings), TPDFFormatSetings);
  38.   if (vHeight = 0) then
  39.     vHeight := StrToFloat(FloatToStrF((vWidth * img.h / img.w), ffNumber,
  40.       14, 2, TPDFFormatSetings), TPDFFormatSetings);
  41.   _out('q ' + FloatToStr(vWidth) + ' 0 0 ' + FloatToStr(vHeight) +
  42.     ' ' + FloatToStr(vX) + ' -' + FloatToStr(vY + vHeight) + ' cm /I' +
  43.     IntToStr(imgcounter) + ' Do Q');
  44. end;
  45.  

Regards
« Last Edit: January 31, 2016, 03:13:52 pm by NumberCruncher »

useroflazarus

  • New Member
  • *
  • Posts: 23
Cyrillic characters are not displayed ((

Code: Pascal  [Select][+][-]
  1. Text(2,18,'АБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя');

in pdf looks as —¡—¢—£—⁄—¥—ƒ—§—¤—'—“—«—‹—›—fi—fl—?—–—†—‡—·—???—¶—•—‚—„

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
@useroflazarus:  I have never used JPDF, but was just wondering. Did you embed a font and select that font to display the Cyrillic text? Obviously not all fonts can display all glyphs.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

jujibo

  • Full Member
  • ***
  • Posts: 114
Cyrillic characters are not displayed ((

Code: Pascal  [Select][+][-]
  1. Text(2,18,'АБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя');

in pdf looks as —¡—¢—£—⁄—¥—ƒ—§—¤—'—“—«—‹—›—fi—fl—?—–—†—‡—·—???—¶—•—‚—„

AFAIK, not supported.

From README:

- Support the main fonts (Helvetica [Arial], Times, Courier, Symbol and Zapfdingbats);
- Support the styles (bold, italic and/or underline);


useroflazarus

  • New Member
  • *
  • Posts: 23
hmm, now characters looks as РђР‘Р’Р“Р”Р•РЃР–Р—Р˜РљР›РњРќРћРџР РЎРўРЈР¤РҐР¦Р§РЁР©РЄР«Р¬Р-ЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя

source code:

Code: Pascal  [Select][+][-]
  1.        //Page 1
  2.        AddPage(poDefault,CP1251);
  3.        SetFont(ffTimes,fsNormal,8,CP1251);
  4.        Text(2,25,'АБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя');

Jan_

  • New Member
  • *
  • Posts: 17
Hey,

got some strange thing here:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. uses classes, sysutils,libjpfpdf;
  4.  
  5. var
  6.   i:integer;
  7.    pdfdoc: TJPFpdf;
  8. begin
  9.  
  10.      pdfdoc := TJPFpdf.Create;
  11.      for i:=0 to 100 do
  12.      begin
  13.  
  14.        pdfdoc.AddPage();
  15.        pdfdoc.SetFont(ffTimes,fsNormal,8);
  16.        pdfdoc.Text(20,30,' '+inttostr(i)+' ');
  17.      end;
  18.      pdfdoc.SaveToFile('liste.pdf');
  19.      pdfdoc.Free;
  20. end.
  21.  

when i run the program a pdf with 101 pages is created. only on page 1 stands 0
all other pages are empty.
what had i did wrong?

Jan_

  • New Member
  • *
  • Posts: 17
i found it.

There is a bug, if you using the same Font over the pages.
just change to another font and back, this worked for me.:
Code: Pascal  [Select][+][-]
  1.        pdfdoc.SetFont(ffTimes,fsBold,8);
  2.        pdfdoc.SetFont(ffTimes,fsNormal,8);



Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. uses classes, sysutils,libjpfpdf;
  4.  
  5. var
  6.   i:integer;
  7.    pdfdoc: TJPFpdf;
  8. begin
  9.  
  10.      pdfdoc := TJPFpdf.Create;
  11.      for i:=0 to 100 do
  12.      begin
  13.  
  14.        pdfdoc.AddPage();
  15.        pdfdoc.SetFont(ffTimes,fsBold,8);
  16.        pdfdoc.SetFont(ffTimes,fsNormal,8);
  17.        pdfdoc.Text(20,30,' '+inttostr(i)+' ');
  18.      end;
  19.      pdfdoc.SaveToFile('liste.pdf');
  20.      pdfdoc.Free;
  21. end.

useroflazarus

  • New Member
  • *
  • Posts: 23
Hello. Some fixes for the Cyrillic encoding.
fixed functions (procedures):
TJPFpdf.Text
TJPFpdf._enddoc
TJPFpdf.Cell

in the attachment an example and source code.

PhilLu

  • New member
  • *
  • Posts: 8
Hello,
is there a way to convert pdf to tif?
Thanks,
Phil

Have a nice X'mas  :P

useroflazarus

  • New Member
  • *
  • Posts: 23
Compression does not work correctly with fpc 3.1.1.

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Thanks to useroflazarus for your update. Under Windows I add some more used accented letters for CP1252. It works fine:

Code: Pascal  [Select][+][-]
  1.    end else if Self.pFonts[vu].CodePage = CP1252 then begin
  2.       _newobj();
  3.       _out('<<');
  4.       _out('/Type /Encoding');
  5.       _out('/BaseEncoding /WinAnsiEncoding');
  6.       _out('/Differences [');
  7.       _out('224 /agrave');
  8.       _out('226 /acircumflex');
  9.       _out('228 /adiaeresis');
  10.       _out('231 /ccedilla');
  11.       _out('232 /egrave');
  12.       _out('233 /eacute');
  13.       _out('234 /ecircumflex');
  14.       _out('235 /ediaeresis');
  15.       _out('239 /idiaeresis');
  16.       _out('246 /odiaeresis');
  17.       _out('249 /ugrave');
  18.       _out('252 /udiaeresis');
  19.       _out(']');
  20.       _out('>>');
  21.       _out('endobj');
  22.  
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

 

TinyPortal © 2005-2018