Comments (13)
Ah I see, yes that example has the same issue.
Basically it just makes the page the same size in points (inches) as the image is in pixels. Normally you would have something like 72 dots (pixels) per inch. I think they just make them the same to make the example very easy to use/read, but it might look a little odd if you mix it with normally sized pages and/or add other things to the same page.
from go-pdfium.
Hi! Can you give me your Go code so I can see what's wrong with it?
from go-pdfium.
Everything is supported in both implementations, WASM and CGO, that it is not working is a bug.
from go-pdfium.
I haven't figured it out yet, but:
- It can load the image fine in WebAssembly, I have validated this by checking the pixel size with FPDFImageObj_GetImagePixelSize and actually rendering the bitmap in Go with FPDFImageObj_GetBitmap/FPDFBitmap_GetBuffer, and the image looks like what it should be
- The image object is added to the PDF content
- The image object content (XObject) is not added to the PDF content
from go-pdfium.
What I do want to add:
You seem to be mixing pixel sizes (from FPDFImageObj_GetImagePixelSize) with point sizes (in the matrix and FPDFPage_New). This should work, but it will make a very big PDF (in terms of inches), and if you want to add anything else to the page it might give you some issues.
from go-pdfium.
@jerbob92
Thanks for the reply.
This is the kind of code we are working on.
type matrix struct {
a float32
b float32
c float32
d float32
e float32
f float32
}
func newMatrix(a, b, c, d, e, f float32) *matrix {
m := matrix{
a: a,
b: b,
c: c,
d: d,
e: e,
f: f,
}
if m.a == 0 {
m.a = 1
}
if m.d == 0 {
m.d = 1
}
return &m
}
func newDefaultMatrix() *matrix {
return newMatrix(0, 0, 0, 0, 0, 0)
}
func (m *matrix) multiply(other *matrix) *matrix {
return newMatrix(
m.a*other.a+m.b*other.c,
m.a*other.b+m.b*other.d,
m.c*other.a+m.d*other.c,
m.c*other.b+m.d*other.d,
m.e*other.a+m.f*other.c+other.e,
m.e*other.b+m.f*other.d+other.f,
)
}
func (m *matrix) scale(x, y float32) *matrix {
return m.multiply(newMatrix(x, 0, 0, y, 0, 0))
}
func newImageToPage(ctx context.Context, doc references.FPDF_DOCUMENT, imageBuffer []byte) error {
instance := GetInstance(ctx)
img, err := instance.FPDFPageObj_NewImageObj(&requests.FPDFPageObj_NewImageObj{
Document: doc,
})
if err != nil {
return err
}
imgObject := img.PageObject
defer closePageObject(ctx, imgObject)
_, err = instance.FPDFImageObj_LoadJpegFile(&requests.FPDFImageObj_LoadJpegFile{
ImageObject: imgObject,
FileReader: bytes.NewReader(imageBuffer),
FileReaderSize: int64(len(imageBuffer)),
})
if err != nil {
return err
}
size, err := instance.FPDFImageObj_GetImagePixelSize(&requests.FPDFImageObj_GetImagePixelSize{
ImageObject: imgObject,
})
if err != nil {
return err
}
m := newDefaultMatrix().scale(float32(size.Width), float32(size.Height))
_, err = instance.FPDFImageObj_SetMatrix(&requests.FPDFImageObj_SetMatrix{
ImageObject: imgObject,
Transform: structs.FPDF_FS_MATRIX{
A: m.a,
B: m.b,
C: m.c,
D: m.d,
E: m.e,
F: m.f,
},
})
if err != nil {
return err
}
page, err := instance.FPDFPage_New(&requests.FPDFPage_New{
Document: doc,
Width: float64(size.Width),
Height: float64(size.Height),
})
if err != nil {
return err
}
defer ClosePage(ctx, page.Page)
_, err = instance.FPDFPage_InsertObject(&requests.FPDFPage_InsertObject{
Page: requests.Page{
ByReference: &page.Page,
},
PageObject: imgObject,
})
if err != nil {
return err
}
_, err = instance.FPDFPage_GenerateContent(&requests.FPDFPage_GenerateContent{
Page: requests.Page{
ByReference: &page.Page,
},
})
if err != nil {
return err
}
if err != nil {
return err
}
return nil
}
from go-pdfium.
@jerbob92
I'd be happy to check 🙏.
from go-pdfium.
I have looked into it and this seems to be an issue with the WebAssembly version, when I try it in the CGO version it does work, I will investigate a bit more and add some tests for it.
from go-pdfium.
Thank you for investigating this.
Is this not supported on the Wasm side and there is nothing I can do with this library?
from go-pdfium.
I wish I could help, but my lack of skills makes it difficult to modify this library yet.
from go-pdfium.
This should be fixed in v1.6.1!
from go-pdfium.
Thank you!
If I have any problems I will let you know👍
from go-pdfium.
I see, thanks.
I was referring to this.
https://github.com/pypdfium2-team/pypdfium2
from go-pdfium.
Related Issues (20)
- how to run a demo HOT 8
- segmentation violation when using a custom ReadSeeker HOT 2
- api:GetPageTextStructured The extracted information has repeat areas HOT 7
- Android failed to use webassembly HOT 1
- Any plans for XFA/V8? HOT 5
- How to install and configure the windows Msys2 environment
- Web assembly implementation build error after v1.12.0 upgrade HOT 4
- Automatically create release with new C library release HOT 1
- Web assembly HOT 77
- Add Mac OS arm64 build support HOT 7
- A size of 0 in FPDF_GetMetaText in GetMetaData should not result in an error HOT 1
- Bitmap generation with alternative fonts HOT 12
- improve doc: how to choose the right parameters for multithreading HOT 22
- windows 7 32 compile error HOT 2
- Concurrent read and write to FileReaders - Web Assembly HOT 3
- Library not loaded on macOS HOT 4
- Retrieving "structured" paths HOT 1
- WebAssembly: module closed with exit_code(1) HOT 7
- Pdf parser HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-pdfium.