Recent

Author Topic: Error On using fpPdf  (Read 415 times)

loadymf

  • New Member
  • *
  • Posts: 10
Error On using fpPdf
« on: December 12, 2023, 12:34:45 am »
 
Error using fpPdf, because the original FPPDF can not be step-by-step debugging I made a copy of FPPDF and renamed it, but there was an error using it. There is no problem using the original FPPDF.
my code


Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button5Click(Sender: TObject);
  2. var
  3.   FontID, FontBoldID: Integer;
  4.   Document: TPDFDocument;
  5.   Section: TPDFSection;
  6.   Page: TPDFPage;
  7.   s:utf8string;
  8.   AColor : TARGBColor;
  9. begin
  10.   Document := TPDFDocument.Create(nil);
  11.   Document.FontDirectory := 'C:\Windows\Fonts';
  12.   Document.StartDocument;
  13.   Document.Infos.Author:='dd颜';//CP936ToUTF8('ymff名字');
  14.   Document.Infos.Producer:='测试pdf';
  15.   Document.Infos.Title:='汉语';
  16.   //Document.Infos.
  17.  
  18.  // FontID := Document.AddFont('simfang.ttf', 'FangSong');
  19.   FontBoldID := Document.AddFont('arial.ttf', 'Arial');
  20.  
  21.   // without poNoEmbeddedFonts it works as expected, but with huge file sizes
  22.   Document.Options := Document.Options + [poPageOriginAtTop, poNoEmbeddedFonts,poUTF16info];
  23.   Section := Document.Sections.AddSection;
  24.  
  25.   Page := Document.Pages.AddPage;
  26.   Section.AddPage(Page);
  27.   AColor  := clBlue;
  28.   page.SetColor(AColor ,true);
  29.   page.DrawRect(67.944 ,763.18 ,252.82 ,42.744,5,true,false,0.0 );
  30.   page.SetFont(FontBoldID ,15);
  31.   Page.WriteText(20, 30, 'This is bold text');
  32.  
  33.  // Document.CreateInfoEntry(true); only add this code in fppdf to update Document.Infos.
  34.   Document.SaveToFile('output.pdf');  

error :invalid type cast at file 'ymfpdf.pas' at line 1756
Code: Pascal  [Select][+][-]
  1. // TODO: (optional improvement) CID -> Unicode mappings, use ranges to generate a smaller CMap
  2. //       See pdfbox's writeTo() method in ToUnicodeWriter.java
  3. procedure TPDFTrueTypeCharWidths.Write(const AStream: TStream);
  4. var
  5.   i: integer;
  6.   s: string;
  7.   lst: TTextMappingList;
  8.   lFont: TTFFileInfo;
  9.   lWidthIndex: integer;
  10. begin
  11.   s := '';
  12.   lst := Document.Fonts[EmbeddedFontNum].TextMapping;
  13.   lst.Sort;
  14.   lFont := Document.Fonts[EmbeddedFontNum].FTrueTypeFile;
  15.  //  lFont.
  16.   {$IFDEF gdebug}
  17.   System.WriteLn('****** isFixedPitch = ', BoolToStr(lFont.PostScript.isFixedPitch > 0, True));
  18.   System.WriteLn('****** Head.UnitsPerEm := ', lFont.Head.UnitsPerEm );
  19.   System.WriteLn('****** HHead.numberOfHMetrics := ', lFont.HHead.numberOfHMetrics );
  20.   {$ENDIF}
  21.  
  22.   { NOTE: Monospaced fonts may not have a width for every glyph
  23.           the last one is for subsequent glyphs.  }
  24.   for i := 0 to lst.Count-1 do
  25.   begin
  26.     if lst[i].GlyphID < lFont.HHead.numberOfHMetrics then
  27.       lWidthIndex := lst[i].GlyphID
  28.     else
  29.       lWidthIndex := lFont.HHead.numberOfHMetrics-1;
  30.     s :=  s + Format(' %d [%d]', [lst[i].GlyphID, TTTFFriendClass(lFont).ToNatural(lFont.Widths[lWidthIndex].AdvanceWidth)])
  31. //This line throws an error,Debug watch display
  32. // lst[i].GlyphID  ,<Error: Cannot access indexed element in expression [>
  33. //TTTFFriendClass(lFont).ToNatural(lFont.Widths[lWidthIndex].AdvanceWidth)  <Error: calling functions not allowed at 33: "(">
  34.   end;
  35.  
  36.   WriteString(s, AStream);
  37. end;    
« Last Edit: December 12, 2023, 12:37:21 am by loadymf »

 

TinyPortal © 2005-2018