Fix long pdf exports
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -18,7 +18,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -134,11 +133,6 @@ func (c *Converter) GeneratePDF(ctx context.Context, htmlDocument []byte, cfg Re
|
|||||||
ctx, cancel = chromedp.NewContext(allocCtx)
|
ctx, cancel = chromedp.NewContext(allocCtx)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
dataURL := fmt.Sprintf(
|
|
||||||
"data:text/html;base64,%s",
|
|
||||||
base64.StdEncoding.EncodeToString(htmlDocument),
|
|
||||||
)
|
|
||||||
|
|
||||||
width, height := getPageDimensions(cfg.PageFormat, cfg.Orientation)
|
width, height := getPageDimensions(cfg.PageFormat, cfg.Orientation)
|
||||||
|
|
||||||
marginTop := cfg.MarginTop.ToInches()
|
marginTop := cfg.MarginTop.ToInches()
|
||||||
@@ -166,8 +160,18 @@ func (c *Converter) GeneratePDF(ctx context.Context, htmlDocument []byte, cfg Re
|
|||||||
log.Bool("printBackground", cfg.PrintBackground),
|
log.Bool("printBackground", cfg.PrintBackground),
|
||||||
)
|
)
|
||||||
|
|
||||||
err := chromedp.Run(ctx,
|
htmlContent := string(htmlDocument)
|
||||||
chromedp.Navigate(dataURL),
|
|
||||||
|
err := chromedp.Run(
|
||||||
|
ctx,
|
||||||
|
chromedp.Navigate("about:blank"),
|
||||||
|
chromedp.ActionFunc(func(ctx context.Context) error {
|
||||||
|
frameTree, err := page.GetFrameTree().Do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot get frame tree: %w", err)
|
||||||
|
}
|
||||||
|
return page.SetDocumentContent(frameTree.Frame.ID, htmlContent).Do(ctx)
|
||||||
|
}),
|
||||||
chromedp.WaitReady("body"),
|
chromedp.WaitReady("body"),
|
||||||
chromedp.ActionFunc(waitUntilDocumentReady),
|
chromedp.ActionFunc(waitUntilDocumentReady),
|
||||||
chromedp.ActionFunc(
|
chromedp.ActionFunc(
|
||||||
|
|||||||
Reference in New Issue
Block a user