github.com/signintech/pdft@v0.5.0/README.md (about)

     1  PDFT
     2  ====
     3  
     4  PDFT is a GO library for creating PDF documents using existing PDFs as template.
     5  This library depend on [gopdf](https://github.com/signintech/gopdf). 
     6  
     7  Tested with PDF template files created from Libre office, Google Docs, Microsoft Word.
     8  
     9   
    10  ### SAMPLE
    11  ```go
    12  var pt pdft.PDFt
    13  err := pt.Open(pdfsource)
    14  if err != nil {
    15  	panic("Couldn't open pdf.")
    16  }
    17  
    18  
    19  err = pt.AddFont("arial", "./arial.ttf")
    20  if err != nil {
    21      t.Error(err)
    22      return
    23  }
    24  
    25  err = pt.SetFont("arial", "", 14)
    26  if err != nil {
    27      panic(err) 
    28  }
    29  
    30  //insert text to pdf
    31  err = pt.Insert("Hi", 1, 10, 10, 100, 100, gopdf.Center|gopdf.Bottom, nil)
    32  if err != nil {
    33      panic(err) 
    34  }
    35  
    36  // insert text to pdf with color
    37  err = pt.Insert("Hi", 1, 10, 10, 100, 100, gopdf.Center|gopdf.Bottom, &FontColor{R: 255, G: 255, B: 255})
    38  if err != nil {
    39      panic(err) 
    40  }
    41  
    42  // measure text width
    43  var textWidth float64
    44  textWidth, err = pt.MeasureTextWidth("Hi")
    45  
    46  // read image file
    47  pic, err := ioutil.ReadFile(picPath)
    48  if err != nil {
    49  	panic("Couldn't read pic.")
    50  }
    51  
    52   
    53  // insert image to pdf
    54  err = pt.InsertImg(pic, 1, 182.0, 165.0, 172.0, 49.0)
    55  if err != nil {
    56  	panic("Couldn't insert image")
    57  }
    58  
    59  // insert image to pdf with cache, avoiding redundant data when inserting same images many times
    60  err = pt.InsertImgWithCache(pic, 1, 182.0, 165.0, 172.0, 49.0)
    61  if err != nil {
    62  	panic("Couldn't insert image")
    63  }
    64  
    65  // Duplicate first page to last page
    66  err = pt.DuplicatePageAfter(1, -1)
    67  if err != nil {
    68  	panic("Couldn't duplicate first page")
    69  }
    70  
    71  // Remove second page
    72  err = pt.RemovePage(2)
    73  if err != nil {
    74  	panic("Couldn't remove targetPage")
    75  }
    76  
    77  err = pt.Save(target)
    78  if err != nil {
    79  	panic("Couldn't save pdf.")
    80  }
    81  ```
    82  
    83