Comments (6)
A fix for this has just landed.
from pdf-core.
@mojavelinux Thinking about this I came to a similar conclusion, if we could wrap the output IO object with something that tracked all writes, it should work. For the diff to be minimal a Decorator object could be written to wrap the passed IO object that implemented the #<<
method and tracked the size of the data as it passes though to the wrapped object's #write
method.
I'm totally open to merging a PR for this.
from pdf-core.
I'll try to put together something asap. I've assigned myself the issue.
from pdf-core.
I took a quick look and it doesn't look like there's an easy way to achieve this.
The problem is that PDF format requires writing some offsets at the end of file. Currently this is implemented by querying size
of io
object at certain points. This only works if io
is empty at the beginning of serialization (which is a bug and probably can produce invalid PDF if non-empty io
is passed in).
STDOUT
is almost never empty. When you fire a terminal and it presents a prompt your STDOUT
is already has something in it.
One solution to this is to cache io
(STDOUT
) position at the beginning of serialization and subtract that when offsets are calculated but this can be messed up if for whatever reason something will write to STDOUT
during rendering. For instance, if you enable warnings and redirect STDERR
to STDOUT
.
The last example also presents the danger of producing invalid PDF since STDOUT
is essentially a shared IO. It's not under exclusive use of Prawn and can be written to at pretty much any time.
Another solution might be an internal buffer (say, a StringIO
) that is used through out the whole rendering and only after it it's dumped to whatever io
object is passed in. This way we can easily calculate all the offsets as we do now, the io
object would only require one write
method and that's it.
I will try and sketch the last approach soon if this is still an issue that needs to be addressed.
from pdf-core.
@mojavelinux @packetmonkey Could you please take a look at my last comment as well as #25?
from pdf-core.
The internal buffer approach is obviously the right one. As to using stdout, that's a user's choice, and they get to keep the results. There is obviously a demand..!
from pdf-core.
Related Issues (15)
- PDF::Core::Text has an implicit dependency on Prawn's map_to_absolute method
- Consider adding a higher level interface similar to add_content but with automated type conversions
- PDF::Core::Text should either be broken up or moved back into Prawn HOT 1
- Validation check issues HOT 3
- undefined method `load_file' for PDF::Core::ObjectStore HOT 4
- failed to allocate memory HOT 5
- Warnings since update version 0.7.0 HOT 21
- Push source code for version 0.8.1 HOT 1
- undefined method `get_page_objects` for PDF::Core::ObjectStore HOT 4
- GPLv2 license file does not match latest revision HOT 1
- Release a new version? HOT 2
- Request for 'STATEMENT' paper size
- Typo in Readme HOT 1
- Limit all PDF decimal numbers to four decimal places HOT 2
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 pdf-core.