signintech / gopdf

A simple library for generating PDF written in Go lang
MIT License
2.59k stars 281 forks source link

How to Rotate Only letter. #138

Open koheiiwamura opened 4 years ago

koheiiwamura commented 4 years ago

I wanna rotate only letter.

when I do this, the "a" is written there.

pdf := gopdf.GoPdf{}
pdf.Start(gopdf.Config{Unit: gopdf.UnitMM, PageSize: gopdf.Rect{W: 140, H: 100}})
pdf.SetMargins(5, 5, 5, 5)
pdf.SetX(50)
pdf.SetY(70)
pdf.CellWithOption(&gopdf.Rect{W: 60, H: 50}, "a", gopdf.CellOption{Align: gopdf.Middle | gopdf.Center, Float: gopdf.Bottom})
スクリーンショット 2020-07-31 17 19 10

How Do I write rotated "a" in same place. I try it, but I can't. https://github.com/signintech/gopdf/issues/90

oneplus1000 commented 4 years ago

This is my complete code.

package main

import (
    "log"

    "github.com/signintech/gopdf"
)

func main() {
    pdf := gopdf.GoPdf{}
    pdf.Start(gopdf.Config{Unit: gopdf.UnitMM, PageSize: gopdf.Rect{W: 140, H: 100}})
    pdf.AddPage()
    var err error
    err = pdf.AddTTFFont("loma", "../ttf/Loma.ttf")
    if err != nil {
        log.Print(err.Error())
        return
    }
    err = pdf.SetFont("loma", "", 14)
    if err != nil {
        log.Print(err.Error())
        return
    }
    pdf.SetMargins(5, 5, 5, 5)
    pdf.SetX(50)
    pdf.SetY(70)
    pdf.Rotate(270.0, 100.0, 100.0)
    pdf.CellWithOption(&gopdf.Rect{W: 60, H: 50}, "a", gopdf.CellOption{Align: gopdf.Middle | gopdf.Center, Float: gopdf.Bottom})
    pdf.WritePdf("issue_138.pdf")
}

This is result.

Screen Shot 2563-08-01 at 11 42 31

Is this what want?

lucaslenz commented 1 year ago

I have a question regarding the rotation. I've tried the example above and when I set the default PageSize to A4, the following result is generated

Bildschirmfoto 2023-09-18 um 12 21 06

I have a PDF which can be composed of different pages which are rotated indepently. The default PageSize should be A4. As the pages can originally belong to different PDF files I import them. After that I want to rotate them but this is not really working.

for _, page := range document {
            reader := io.ReadSeeker(bytes.NewReader(uploadedFiles[page.UploadedFileId].Bytes()))

            templateId := pdf.ImportPageStream(
                &reader,
                page.PageNumber+1,
                "/MediaBox",
            )

            pdf.AddPage()

            pdf.UseImportedTemplate(templateId, 0, 0, gopdf.PageSizeA4.W, gopdf.PageSizeA4.H)

            fmt.Printf("Page Rotation %d\n", page.Rotation)
            if page.Rotation == 90 || page.Rotation == 270 {
                pdf.SetX(gopdf.PageSizeA4.W / 2)
                pdf.SetY(gopdf.PageSizeA4.H / 2)
                pdf.Rotate(float64(page.Rotation), pdf.GetX(), pdf.GetY())
            }
        }

My idea was to import the page and afterwards rotate the whole page. Therefore i center the "cursor" and rotate afterwards. But the result is just the "original" PDF (not rotated).

Is that even possible? Can I set PageSize's idividually per page?

vantaboard commented 5 months ago

I have a question regarding the rotation. I've tried the example above and when I set the default PageSize to A4, the following result is generated

Bildschirmfoto 2023-09-18 um 12 21 06

I have a PDF which can be composed of different pages which are rotated indepently. The default PageSize should be A4. As the pages can originally belong to different PDF files I import them. After that I want to rotate them but this is not really working.

for _, page := range document {
          reader := io.ReadSeeker(bytes.NewReader(uploadedFiles[page.UploadedFileId].Bytes()))

          templateId := pdf.ImportPageStream(
              &reader,
              page.PageNumber+1,
              "/MediaBox",
          )

          pdf.AddPage()

          pdf.UseImportedTemplate(templateId, 0, 0, gopdf.PageSizeA4.W, gopdf.PageSizeA4.H)

          fmt.Printf("Page Rotation %d\n", page.Rotation)
          if page.Rotation == 90 || page.Rotation == 270 {
              pdf.SetX(gopdf.PageSizeA4.W / 2)
              pdf.SetY(gopdf.PageSizeA4.H / 2)
              pdf.Rotate(float64(page.Rotation), pdf.GetX(), pdf.GetY())
          }
      }

My idea was to import the page and afterwards rotate the whole page. Therefore i center the "cursor" and rotate afterwards. But the result is just the "original" PDF (not rotated).

Is that even possible? Can I set PageSize's idividually per page?

It looks like this should be it's own independent issue. I would recommend creating a new issue so that @oneplus1000 can close this one since it has been open for a long time now.