Giter VIP home page Giter VIP logo

gofpdf's People

Contributors

benoitkugler avatar claudiofelber avatar d1ngd0 avatar danmeyers avatar darkfreedman avatar darrenmcc avatar divan avatar echa avatar eiskasten avatar flibustenet avatar hypertornado avatar hyzgh avatar jacobalberty avatar jelmersnoeck avatar joewestcott avatar jung-kurt avatar kveselkov avatar marcus-downing avatar moogle19 avatar mrtsbt avatar phpdave11 avatar rubenn avatar ruudk avatar sbinet avatar sbstjn avatar seletskiy avatar slomek avatar stanim avatar tim-st avatar wmatusiak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gofpdf's Issues

Best way to access css file when using HTML interface?

Hello, I have a use case where we are generating PDFs using the HTML interface, and the HTML references a CSS stylesheet on the local file system. Looking through the docs, is appears as though file attachments might be the blessed way of being able to refer to that stylesheet, but I am not sure.

Is this a use case that is currently supported? Or would we need to inline the CSS?

incorrect font flag value

I think the SmallCap value defined in def (line 651) as 1 << 18 should be 1 << 17, so that the "bit position" defined in the SPEC, part 9.8.2 (Font Descriptor Flag) in Table 123 (Font flag), is actually 18.
As an other evidence, consider that ForceBold has the same value 1 << 18, which is certainly a mistake.

Improve documentation for AddUTF8Font

AddUTF8Font appears to have the documentation copied from AddFont. I suggest the following replacement might be an improvement.

// AddUTF8Font imports a TrueType font with utf-8 symbols and makes it available.
// The TTF font file must be present in the font directory, or a subdirectory. If it is 
// not found, an error is set.
//
// familyStr specifies the font family. The name can be chosen arbitrarily. If it
// is a standard family name, it will override the corresponding font. This
// string is used to subsequently set the font with the SetFont method.
//
// styleStr specifies the font style. Acceptable values are (case insensitive) the
// empty string for regular style, "B" for bold, "I" for italic, or "BI" or
// "IB" for bold and italic combined.
//
// fileStr specifies the name with ".ttf" extension of the font file to be added.
// The file will be loaded from the font directory specified in the call to New()
// or SetFontLocation(). fileStr can include a relative path, meaning the font can
// be loaded from a subdirectory of the font directory.

Also, the other Add..Font methods mention family instead of familyStr, style instead of styleStr.

Possible financial participation for the maintainer ?

Hello,
Thank you for this fork!
I am a freelancer, and I use this library for my clients, if you plan to maintain it I encourage you to allow a financial participation.
I would be happy to at least pay a small % for each dev, to the maintainer of this library.

And I'm probably not the only one :p

Embedding files

There is a diffuser format of PDF called PDF/A-2 that is allowing embedding other contents at the pdf file, let's say embedding xml file inside the pdf file, is this supported by this package, if yes, how? Thanks.

Maintain a fork ?

Hi,

Would you like to maintain a fork of gofpdf ? I cannot do it myself but i could help.

Charset weirdness despite using core PDF fonts

Steps to reproduce:

  1. create a new *gofpdf.FPDF:

    pdf := gofpdf.New("P", "pt", "Letter", "")
  2. set the font to Courier 12:

    pdf.SetFont("courier", "", 12)
  3. write a bullet character, (U+2022):

    pdf.Write("•", 12)
  4. write the PDF to a file:

    f, err := os.Create("/tmp/output.pdf")
    if err != nil {
    	t.Fatal(err)
    }
    defer f.Close()
    
    pdf.Output(f)

Expected:

  • Bullet is written to rendered PDF

Actual:

  • Rendered PDF shows •

Discussion:

I admit, I haven't dug deep enough to quite get the state of GoFPF UTF-8 support. My first thought was that I needed to add UTF-8 font, but according to the AddUTF8Font docs,

It is not necessary to call this function for the core PDF fonts
(courier, helvetica, times, zapfdingbats).

Regardless, is that the workaround? Or is there a workaround? Are we currently limited to certain code pages?

[PANIC] Index out of range

Hi, I have an index out of range with [email protected]

panic: runtime error: index out of range [53] with length 0
goroutine 66 [running]:
github.com/phpdave11/gofpdf.(*Fpdf).write(0xc0003ac000, 0x4020000000000000, {0xc0004eaf00?, 0x4?}, 0x4?, {0x0, 0x0})
         /root/go/pkg/mod/github.com/phpdave11/[email protected]/fpdf.go:2839 +0xbea
github.com/phpdave11/gofpdf.(*Fpdf).Write(...)
         /root/go/pkg/mod/github.com/phpdave11/[email protected]/fpdf.go:2901
[...]

There is happening after a call to Write.
Used font are UbuntuFont

strBuff = fmt.Sprintf(
    "\n%s, %s, %s %s\n", 
    data.Simple["se-addr-num"], 
    data.Simple["se-addr-complement"], 
    data.Simple["se-addr-code"], 
    data.Simple["se-addr-commune"],
)

log.Println("DEBUG PANIC: ", strBuff)
pdf.Write(8, strBuff)

🤔

Failed to read pdf: Failed to read xref table

can‘t paste pdf which download from net on an exist pdf.
this is the code:

package main

import (
	"bytes"
	"io"
	"io/ioutil"
	"net/http"

	"github.com/phpdave11/gofpdf"
	"github.com/phpdave11/gofpdf/contrib/gofpdi"
)

func pdfDownload(url string) ([]byte, error) {
	resp, err := http.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	return ioutil.ReadAll(resp.Body)
}

func main() {
	u := "https://kpserverdev-1251506165.cos.ap-shanghai.myqcloud.com/invoice/upload/20201844_83371_1603161368632.pdf"
	resp, err := http.Get(u)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	strem, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	ioseeker := io.ReadSeeker(bytes.NewReader(strem))
	pdf := gofpdf.New("P", "pt", "A4", "/MediaBox")
	imp := gofpdi.ImportPageFromStream(pdf, &ioseeker, 1, "/MediaBox")
	pdf.AddPage()
	gofpdi.UseImportedTemplate(pdf, imp, 20, 50, 150, 0)
	if err := pdf.OutputFileAndClose("./out.pdf"); err != nil {
		panic(err)
	}
}

Page size increase after use another file as PDF as a template

Hi guys,
I am tried to update existing pdf file, just add some text and picture, and got some strange behaviour. If you import file as template and then save it even without any changes at all page size increase by 2.83 times. For example original file was 612 * 792 px then after import all pages and save it again (without any changes) it is became 1734 * 2245 px, if I try to repeat that exercise next step will be 4917 * 6363 px, and so on. Even if I specify sizeType in code it does not help at all. I think it is an issue.

Print PDF from HTML string

Hey` guys,

I am trying to figure out why my code is not working as expected.
I have markdown source code, which I am converting with: https://github.com/gomarkdown/markdown
It is giving me some html string, which I am trying to print to a PDF, but when I print it to a PDF the HTML tags are ignored and just plaintext is printed.

My code:

_, lineHt := pdf.GetFontSize()
html := pdf.HTMLBasicNew()
convertedHTML := convertMarkdown(subchapter.Content)
println(string(convertedHTML))
html.Write(lineHt, string(convertedHTML))
err := pdf.OutputFileAndClose(fmt.Sprintf("%s.pdf", course.Name))
func convertMarkdown(subchapterContent string) []byte {
	extensions := parser.CommonExtensions | parser.OrderedListStart | parser.NoEmptyLineBeforeBlock
	p := parser.NewWithExtensions(extensions)
	doc := p.Parse([]byte(subchapterContent))

	htmlFlags := html.CommonFlags | html.HrefTargetBlank
	opts := html.RendererOptions{Flags: htmlFlags}
	renderer := html.NewRenderer(opts)

	return markdown.Render(doc, renderer)
}

The convert returns me this string

<h2>Chapter outcomes</h2>

<p>At the end of this page you should be able to:</p>

<ul>
<li>Explain how the Cloud Native Computing Foundation (CNCF) defines the Cloud Native terms and their core characteristics.</li>
<li>Describe monolith vs. microservices architecture approaches with examples as well as the benefits and drawbacks of both approaches.</li>
<li>Describe different autoscaling options in Cloud Native environments.</li>
<li>Describe the concept and benefits of serverless computing.</li>
<li>Explain community and governance</li>
<li>Explain the roles and personas that exist within Cloud Native environments and their corresponding tasks?</li>
<li>Describe which open standards are available in Cloud Native world and what they are used for?</li>
</ul>

Release a v1.4.1 or v1.5.0 for go get

Currently

$ go get github.com/phpdave11/gofpdf
go get: github.com/phpdave11/[email protected]: parsing go.mod:
	module declares its path as: github.com/jung-kurt/gofpdf
        but was required as: github.com/phpdave11/gofpdf

It works with go get github.com/phpdave11/gofpdf@master

But maybe you can release a v1.4.1 or v1.5.0 or change the current readme to add @master

Closing files

So I've encountered a problem when using gofpdf library. When importing pages when it reads the file it does not close it. Then I found out that the library can't close it cause it does not have the access to the file opened by this lib. Far as I see that files opened in NewPdfReader and NewPdfWriter cannot be closed outside the lib. So when the libs use the reader and writer the files remain open and cannot be closed. So there should be a public function on pdfReader and pdfWriter that just closes the file. Something like this maybe?

Screenshot 2021-04-26 at 09 46 07

Did I miss understood how something in the library works? Or am I right and if so should I make a PR with the methods that you see in the screenshot or is it simple enough for you to do a quick implementation. Btw the method in the screenshot was not tested just wanted to see how it would be implemented.

Question: is gofpdf accessible?

Hello,

I'm looking into using gofpdf, but my team requires a package that keeps accessibility changes added by adobe acrobat pro, such as accessibility tags and reading order.

Does gofpdf preserve accessibility tags and alternative text for images?

These are necessary to allow blind or low vision users who use a screen reader to access the information on a PDF.

Consider concurrent page generation

For the generation of complex and many-paged documents, it may be useful to perform page generation concurrently. In the program pdfdeck, I use github.com/jung-kurt/gofpdf, which I believe could perform better using phpdave11/gofpdf using concurrent generation.

For example, rendering this deck: https://github.com/ajstarks/dubois-data-portraits/blob/master/baldwin/baldwin.dsh takes about 3.8 seconds on my X1 Carbon 5th Gen, under Linux and 3.5 seconds on a MacBook Pro, Late 2013 running Mac OS 11.4

Note that this deck is 45201976 bytes, 55 slides, with 87 unique images. (in my measurements, image rendering is among the most expensive).

HowTo: SetXmpMetadata

Hi,

I need to set some XMP Metadata but i am clueless of how to use this function? Can you give a short example of how to add additional metadata fields?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.