@@ -147,6 +147,7 @@ struct fz_document_s
147
147
self.isClosed = False
148
148
self.isEncrypted = 0
149
149
self.metadata = None
150
+ self.stream = stream # prevent garbage collection of it
150
151
self.openErrCode = 0
151
152
self.openErrMsg = ' '
152
153
self.FontInfos = []
@@ -158,7 +159,6 @@ struct fz_document_s
158
159
self.openErrCode = self._getGCTXerrcode ()
159
160
self.openErrMsg = self._getGCTXerrmsg ()
160
161
self.thisown = True
161
- self.isClosed = False
162
162
if self.needsPass :
163
163
self.isEncrypted = 1
164
164
else : # we won' t init until doc is decrypted
@@ -219,6 +219,7 @@ struct fz_document_s
219
219
self._outline = None
220
220
self._reset_page_refs()
221
221
self.metadata = None
222
+ self.stream = None
222
223
self.isClosed = True
223
224
self.openErrCode = 0
224
225
self.openErrMsg = ' '
@@ -312,7 +313,7 @@ struct fz_document_s
312
313
limits = pdf_dict_get(gctx, efiles, PDF_NAME_Limits);
313
314
limit1 = NULL;
314
315
limit2 = NULL;
315
- if (limits) // have name limits?
316
+ if (limits) // have name limits?
316
317
{
317
318
limit1 = pdf_to_utf8(gctx, pdf_array_get(gctx, limits, 0));
318
319
limit2 = pdf_to_utf8(gctx, pdf_array_get(gctx, limits, 1));
@@ -374,7 +375,6 @@ struct fz_document_s
374
375
%feature("autodoc","Retrieve embedded file information given its entry number or name.") embeddedFileInfo;
375
376
PyObject *embeddedFileInfo(PyObject *id)
376
377
{
377
- PyObject *infodict = PyDict_New();
378
378
pdf_document *pdf = pdf_document_from_fz_document(gctx, $self);
379
379
Py_ssize_t name_len = 0;
380
380
int n = -1;
@@ -383,22 +383,23 @@ struct fz_document_s
383
383
fz_try(gctx)
384
384
{
385
385
assert_PDF(pdf);
386
- n = FindEmbedded (gctx, id, pdf);
386
+ n = JM_FindEmbedded (gctx, id, pdf);
387
387
if (n < 0) THROWMSG("entry not found");
388
388
}
389
389
fz_catch(gctx) return NULL;
390
390
391
+ PyObject *infodict = PyDict_New();
391
392
// name of file entry
392
393
name = pdf_to_utf8(gctx, pdf_portfolio_entry_name(gctx, pdf, n));
393
394
PyDict_SetItemString(infodict, "name",
394
- JM_UNICODE(name, strlen(name)));
395
+ JM_UNICODE(name, strlen(name)));
395
396
pdf_obj *o = pdf_portfolio_entry_obj(gctx, pdf, n);
396
397
name = pdf_to_utf8(gctx, pdf_dict_get(gctx, o, PDF_NAME_F));
397
398
PyDict_SetItemString(infodict, "file",
398
- JM_UNICODE(name, strlen(name)));
399
+ JM_UNICODE(name, strlen(name)));
399
400
name = pdf_to_utf8(gctx, pdf_dict_get(gctx, o, PDF_NAME_Desc));
400
401
PyDict_SetItemString(infodict, "desc",
401
- JM_UNICODE(name, strlen(name)));
402
+ JM_UNICODE(name, strlen(name)));
402
403
pdf_obj *olen = pdf_dict_getl(gctx, o, PDF_NAME_EF, PDF_NAME_F,
403
404
PDF_NAME_Length, NULL);
404
405
int len = -1;
@@ -423,8 +424,8 @@ struct fz_document_s
423
424
int flen = 0, dlen = 0;
424
425
if (filename) flen = (int) strlen(filename);
425
426
if (desc) dlen = (int) strlen(desc);
426
- if ((flen == 0 ) && (dlen == 0 )) THROWMSG("nothing to change");
427
- int n = FindEmbedded (gctx, id, pdf);
427
+ if ((flen < 1 ) && (dlen < 1 )) THROWMSG("nothing to change");
428
+ int n = JM_FindEmbedded (gctx, id, pdf);
428
429
if (n < 0) THROWMSG("entry not found");
429
430
pdf_obj *entry = pdf_portfolio_entry_obj(gctx, pdf, n);
430
431
@@ -452,13 +453,13 @@ struct fz_document_s
452
453
%feature("autodoc","Retrieve embedded file content given its entry number or name.") embeddedFileGet;
453
454
PyObject *embeddedFileGet(PyObject *id)
454
455
{
455
- PyObject *cont = PyBytes_FromString("") ;
456
+ PyObject *cont = NULL ;
456
457
pdf_document *pdf = pdf_document_from_fz_document(gctx, $self);
457
458
fz_buffer *buf = NULL;
458
459
fz_try(gctx)
459
460
{
460
461
assert_PDF(pdf);
461
- int i = FindEmbedded (gctx, id, pdf);
462
+ int i = JM_FindEmbedded (gctx, id, pdf);
462
463
if (i < 0) THROWMSG("entry not found");
463
464
unsigned char *data;
464
465
buf = pdf_portfolio_entry(gctx, pdf, i);
@@ -492,12 +493,12 @@ struct fz_document_s
492
493
assert_PDF(pdf);
493
494
}
494
495
fz_catch(gctx) return -1;
495
- if (file_len == 0) // no filename given
496
+ if (file_len == 0) // no filename given
496
497
{
497
498
f = name; // take the name
498
499
file_len = name_len;
499
500
}
500
- if (desc_len == 0) // no description given
501
+ if (desc_len == 0) // no description given
501
502
{
502
503
d = name; // take the name
503
504
desc_len = name_len;
@@ -668,6 +669,7 @@ struct fz_document_s
668
669
THROWMSG("decrypted file - save to new");
669
670
pdf_finish_edit(gctx, pdf);
670
671
pdf_save_document(gctx, pdf, filename, &opts);
672
+ pdf->dirty = 0;
671
673
}
672
674
fz_catch(gctx) return NULL;
673
675
return NONE;
@@ -715,6 +717,7 @@ struct fz_document_s
715
717
res = fz_new_buffer(gctx, 1024);
716
718
out = fz_new_output_with_buffer(gctx, res);
717
719
pdf_write_document(gctx, pdf, out, &opts);
720
+ pdf->dirty = 0;
718
721
len = fz_buffer_storage(gctx, res, &c);
719
722
r = PyBytes_FromStringAndSize(c, len);
720
723
}
@@ -1612,6 +1615,7 @@ if links:
1612
1615
self.thisown = False
1613
1616
self.__swig_destroy__(self)
1614
1617
self.Graftmaps = {}
1618
+ self.stream = None
1615
1619
self._reset_page_refs = DUMMY
1616
1620
self.__swig_destroy__ = DUMMY
1617
1621
self.isClosed = True
0 commit comments