summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-write.c
AgeCommit message (Collapse)Author
2016-07-08Separate close and drop functionality for devices and writers.Tor Andersson
Closing a device or writer may throw exceptions, but much of the foreign language bindings (JNI and JS) depend on drop to never throw an exception (exceptions in finalizers are bad).
2016-07-06Fix garbage collection and page grafting for indirect reference chains.Tor Andersson
The mark & sweep pass of garbage collection, and resolving indirect objects when grafting objects was following the full chain of indirect references. In the unusual case where a numbered object is itself only an indirect reference to another object, this intermediate numbered object would be missed both when marking for garbage collection, and when copying objects for grafting. Add a function to resolve only one step for these two uses. The following is an example of a file that would break during garbage collection if we follow full indirect reference chains: %PDF-1.3 1 0 obj <</Type/Catalog /Foo[2 0 R 3 0 R]>> endobj 2 0 obj 4 0 R endobj 3 0 obj 5 0 R endobj 4 0 obj <</Length 1>> stream A endstream endobj 5 0 obj <</Length 1>> stream B endstream endobj
2016-07-06pdf: Drop generation number from public interfaces.Tor Andersson
The generation number is only needed for decryption, and is assumed to be zero or irrelevant for all other uses. Store the original object number and generation in the xref slot, so that we can decrypt them even when the objects have been renumbered, without needing to pass the original object number around through the stream loading APIs.
2016-06-17Add device space transform state to draw device.Tor Andersson
Allows us to remove the out parameter 'transform' from fz_begin_page.
2016-06-17Use 'size_t' instead of int as appropriate.Robin Watts
This silences the many warnings we get when building for x64 in windows. This does not address any of the warnings we get in thirdparty libraries - in particular harfbuzz. These look (at a quick glance) harmless though.
2016-06-16Add PNG output for mutool convert.Tor Andersson
2016-06-16Return options struct argument from pdf_parse_write_options.Tor Andersson
Makes it easier to chain function calls.
2016-06-16Fix crash due to double closing output in pdf_save_document.Robin Watts
Broken due to refactoring. Thanks to Michael for spotting this.
2016-06-14Fix typos in various parts of the code.Sebastian Rasmussen
2016-06-13Add pdf_write_document.Robin Watts
Allow us to write a document to an fz_output as opposed to just a filename. We cannot write digital signatures in this method though. Will ponder that in a later commit.
2016-06-13Bug 696822: Refuse to save a pdf file incrementally if it would break.Robin Watts
If a file cannot be saved incrementally, then don't accept that as an option. In practise this means if someone asks to save a file incrementally, and it was repaired, or it uses encryption then throw an error. Add a new function to ask if it's safe to save a file incrementally, and use that in the appropriate places.
2016-05-13murun: Add document writer object.Tor Andersson
2016-05-13Add pdf write support to mutool convert.Tor Andersson
2016-05-13Add long output option parsing.Tor Andersson
Use comma-separated list of flags and key/value pairs, for example: "linearize,resolution=72,colorspace=gray"
2016-04-27Tweak pdf-write option handling.Tor Andersson
The handling of not-decompressing images/fonts was geared towards pdfclean usage; but now that we can create new PDF files, it makes more sense to ask for images and fonts to be compressed, rather than asking for them not to be decompressed with quirky interaction with the 'expand' and 'deflate' flags. If -f or -i are set, we will never decompress images, and we will compress them if they are uncompressed. If -d is set, we will first decompress all streams (module -f or -i). If -z is set, we will then compress all uncompressed streams.
2016-04-27Fix 696649: remove fz_rethrow_message calls.Tor Andersson
2016-04-26Update mutool clean sanitize to clean annotations too.Robin Watts
2016-04-22pdf: Remember to drop objects inserted into dicts.Sebastian Rasmussen
2016-04-11Bug 696696: Avoid leak when cleaning with sanitize.Robin Watts
If we rewrite a page content stream, and then drop that entire page we shouldn't leak the buffer. Or to put it another way, when we change the obj for an xref entry, ditch the cached stm_buf.
2016-03-14Take pdf_obj argument to pdf_is_stream.Tor Andersson
2016-03-01Rename pdf_new_ref to pdf_add_object.Tor Andersson
2016-03-01Add const to filename string.Tor Andersson
2016-02-25Skip the newline before endstream if the stream ends in a newline.Tor Andersson
2016-02-24Always write a newline after pdf_print_obj.Tor Andersson
2016-02-22Fix flaw in printing objects.Robin Watts
When printing a PDF object to a file, if it was a name, then we'd output without a required \n. For example: 10 0 obj /SomeNameOrOtherendobj This would trip gs up.
2016-02-22Add some helpful debugging code to the mark and sweep code.Robin Watts
2016-01-20Various formatting cleanups.Tor Andersson
2015-12-18Remove fz_save_document and use pdf_save_document directly instead.Tor Andersson
In preparation of adding pdf_write_document that writes a document to a fz_output stream.
2015-12-15Rename fz_write_x to fz_save_pixmap_as_x or fz_save_bitmap_as_x.Tor Andersson
Separate naming of functions that save complete files to disk from functions that write data to streams.
2015-12-11Use fz_output instead of FILE* for most of our output needs.Tor Andersson
Use fz_output in debug printing functions. Use fz_output in pdfshow. Use fz_output in fz_trace_device instead of stdout. Use fz_output in pdf-write.c. Rename fz_new_output_to_filename to fz_new_output_with_path. Add seek and tell to fz_output. Remove unused functions like fz_fprintf. Fix typo in pdf_print_obj.
2015-10-14Fix incremental xref stream.Simon Reinhardt
When writing incremental xref streams, the opts->use_list entry of the last object, i.e. of the xref stream object itself, was left uninitialized. This resulted in a random value, 0 or 1, being written into the xref stream. Also, always write a newline before the endstream keyword, as that shall be done for xref streams and should be done for all other streams.
2015-08-27Support several levels of incremental xrefPaul Gardiner
This fixes bug #696123 by allowing multiple signatures each to be written to the document in a separate incemental update. Add count num_incremental_sections to keep track of the number of incremental sections. Add xref_base, which can be set between 0 and num_incremental_sections inclusive to access different versions of the document. Add disallow_new_increments flag that stops new incremental sections being provoked by the creation of an xref stream. Move the unsaved_sigs list from the document structure to the xref structure. With this commit in place, the lists will never grow beyond length one, but we've maintained the list structure in case other cases need supporting in the future. Add an end offset field to the xref structure, so that during completion of signatures the document length of the various incremental versions of the document are available. Factor out functions for storing unsaved signatures and for checking if an object is an unsaved signature. Do deep copy of objects that require the holding of several versions.
2015-08-27In pdf_write_document, factor out init/fin of pdf_write_optionsPaul Gardiner
This is work towards bug #696123
2015-08-27Fix bug in setting of opts->ofs_listPaul Gardiner
In the incremental case, we should update ofs_list only when actually writing an object to file. This is work towards bug #696123.
2015-06-05Fix mutool clean for FZ_LARGEFILE case.Robin Watts
We were allocating the ofs array as ints and then filling it with fz_off_t's.
2015-05-15Support pdf files larger than 2Gig.Robin Watts
If FZ_LARGEFILE is defined when building, MuPDF uses 64bit offsets for files; this allows us to open streams larger than 2Gig. The downsides to this are that: * The xref entries are larger. * All PDF ints are held as 64bit things rather than 32bit things (to cope with /Prev entries, hint stream offsets etc). * All file positions are stored as 64bits rather than 32. The implementation works by detecting FZ_LARGEFILE. Some #ifdeffery in fitz/system.h sets fz_off_t to either int or int64_t as appropriate, and sets defines for fz_fopen, fz_fseek, fz_ftell etc as required. These call the fseeko64 etc functions on linux (and so define _LARGEFILE64_SOURCE) and the explicit 64bit functions on windows.
2015-04-16mutool clean -z option to compress streams.Tor Andersson
2015-04-16ASCIIHexEncode inline images during sanitization if do_ascii is set.Tor Andersson
2015-03-25Bug 695864: Avoid assertion if a file is saved incrementally twice.Robin Watts
The actual fix implemented here is to bale out of pdf_write_document if we are updating incrementally and the file has not changed.
2015-03-25Fix Mutool; was broken due to printf changes.Robin Watts
Move pdf-write.c over to calling fz_fprintf for all places in we need printf, and fputs elsewhere.
2015-03-24Update our printf to cope with various useful extensions.Robin Watts
Ensure that %010d works. Ensure that we can output 64 bit values (%ll{d,u,x}). Ensure that we can output size_t and fz_off_t (%z{d,u,x} and %Z{d,u,x}). fz_off_t isn't defined yet (it will be introduced by a commit that depends on this one), so for now, we put a stub definition in printf.c that we will remove later.
2015-03-24Rework handling of PDF names for speed and memory.Robin Watts
Currently, every PDF name is allocated in a pdf_obj structure, and comparisons are done using strcmp. Given that we can predict most of the PDF names we'll use in a given file, this seems wasteful. The pdf_obj type is opaque outside the pdf-object.c file, so we can abuse it slightly without anyone outside knowing. We collect a sorted list of names used in PDF (resources/pdf/names.txt), and we add a utility (namedump) that preprocesses this into 2 header files. The first (include/mupdf/pdf/pdf-names-table.h, included as part of include/mupdf/pdf/object.h), defines a set of "PDF_NAME_xxxx" entries. These are pdf_obj *'s that callers can use to mean "A PDF object that means literal name 'xxxx'" The second (source/pdf/pdf-name-impl.h) is a C array of names. We therefore update the code so that rather than passing "xxxx" to functions (such as pdf_dict_gets(...)) we now pass PDF_NAME_xxxx (to pdf_dict_get(...)). This is a fairly natural (if widespread) change. The pdf_dict_getp (and sibling) functions that take a path (e.g. "foo/bar/baz") are therefore supplemented with equivalents that take a list (pdf_dict_getl(... , PDF_NAME_foo, PDF_NAME_bar, PDF_NAME_baz, NULL)). The actual implementation of this relies on the fact that small pointer values are never valid values. For a given pdf_obj *p, if NULL < (intptr_t)p < PDF_NAME__LIMIT then p is a literal entry in the name table. This enables us to do fast pointer compares and to skip expensive strcmps. Also, bring "null", "true" and "false" into the same style as PDF names. Rather than using full pdf_obj structures for null/true/false, use special pointer values just above the PDF_NAME_ table. This saves memory and makes comparisons easier.
2015-03-24Don't pass interpreter context to pdf_processor opcode callbacks.Tor Andersson
Update buffer and filter processors. Filter both colors and stroke states. Move OCG hiding logic into interpreter.
2015-03-20Automatically update /Length and /Filter in pdf_update_stream.Tor Andersson
2015-03-01Bug 695658: Fix crash with mutool clean -l -aRobin Watts
We were failing to allow for the change in length of the hint stream caused by the ascii encoding when calculating offsets.
2015-02-27Bug 695853: Fix pdf clean operation with invalid refs in input file.Robin Watts
MuPDF (and other PDF readers) treat invalid references as 'null' objects. For instance, in the supplied file, object 239 is supposedly free, but a reference is made to it. When cleaning (or linearising) a file, we renumber objects; such illegal refs then end up pointing somewhere else. The workaround here is simply to spot the invalid refs during the mark phase, and to set the referencing to null.
2015-02-25Add post processing option to page operator cleaning.Robin Watts
In order to be able to watermark etc, we want the ability to add more operators/resources after page cleaning. Add a post processing hook to enable this to be done more easily.
2015-02-17Add ctx parameter and remove embedded contexts for API regularity.Tor Andersson
Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap.
2015-02-17Rename fz_close_* and fz_free_* to fz_drop_*.Tor Andersson
Rename fz_close to fz_drop_stream. Rename fz_close_archive to fz_drop_archive. Rename fz_close_output to fz_drop_output. Rename fz_free_* to fz_drop_*. Rename pdf_free_* to pdf_drop_*. Rename xps_free_* to xps_drop_*.
2014-11-26Change xref representation to cope better with sparse xrefs.Robin Watts
Currently each xref in the file results in an array from 0 to num_objects. If we have a file that has been updated many times this causes a huge waste of memory. Instead we now hold each xref as a list of non-overlapping subsections (exactly as the file holds them). Lookup is therefore potentially slower, but only on files where the xrefs are highly fragmented (i.e. where we would be saving in memory terms). Some parts of our code (notably the file writing code that does garbage collection etc) assumes that lookups of object entry pointers will not change previous object entry pointers that have been looked up. To cope with this, and to cope with the case where we are updating/creating new objects, we introduce the idea of a 'solid' xref. A solid xref is one where it has a single subsection record that spans the entire range of valid object numbers for a file. Once we have ensured that an xref is 'solid', we can safely work on the pointers within it without fear of them moving. We ensure that any 'incremental' xref is solid. We also ensure that any non-incremental write makes the xref solid.