基类已重命名,因为它们还允许使用 ByteIO 流而不是文件进行操作。此外,​strict​ 参数将默认值从 ​strict=True​ 更改为 ​strict=False​。

  • PdfFileReaderPdfReader

  • PdfFileWriterPdfWriter

  • PdfFileMergerPdfMerger

PdfFileReader 和 PdfFileMerger 不再有 ​overwriteWarnings​ 参数。新行为是 ​overwriteWarnings=False​。

函数、方法和属性名称

在 PyPDF2.xmp.XmpInformation:

  • rdfRootrdf_root

  • xmp_createDatexmp_create_date

  • xmp_creatorToolxmp_creator_tool

  • xmp_metadataDatexmp_metadata_date

  • xmp_modifyDatexmp_modify_date

  • xmpMetadataxmp_metadata

  • xmpmm_documentIdxmpmm_document_id

  • xmpmm_instanceIdxmpmm_instance_id

在 PyPDF2.generic:

  • readObjectread_object

  • convertToIntconvert_to_int

  • DocumentInformation.getTextDocumentInformation._get_text : 通常不应使用此方法;如果您需要,请告诉我。

  • readHexStringFromStreamread_hex_string_from_stream

  • initializeFromDictionaryinitialize_from_dictionary

  • createStringObjectcreate_string_object

  • TreeObject.hasChildrenTreeObject.has_children

  • TreeObject.emptyTreeTreeObject.empty_tree

在很多地方:

  • getObjectget_object

  • writeToStreamwrite_to_stream

  • readFromStreamread_from_stream

PdfReader 类:

  • reader.getPage(pageNumber)reader.pages[page_number]

  • reader.getNumPages() / reader.numPageslen(reader.pages)

  • getDocumentInfometadata

  • flattenedPages 属性➔ flattened_pages

  • resolvedObjects 属性 ➔ resolved_objects

  • xrefIndex 属性 ➔ xref_index

  • getNamedDestinations / namedDestinations 属性 ➔ named_destinations

  • getPageLayout / pageLayoutpage_layout 属性

  • getPageMode / pageModepage_mode 属性

  • getIsEncrypted / isEncryptedis_encrypted 属性

  • getOutlinesget_outlines

  • readObjectHeaderread_object_header

  • cacheGetIndirectObjectcache_get_indirect_object

  • cacheIndirectObjectcache_indirect_object

  • getDestinationPageNumberget_destination_page_number

  • readNextEndLineread_next_end_line

  • _zeroXref_zero_xref

  • _authenticateUserPassword_authenticate_user_password

  • _pageId2Num 属性 ➔ _page_id2num

  • _buildDestination_build_destination

  • _buildOutline_build_outline

  • _getPageNumberByIndirect(indirectRef)_get_page_number_by_indirect(indirect_ref)

  • _getObjectFromStream_get_object_from_stream

  • _decryptObject_decrypt_object

  • _flatten(..., indirectRef)_flatten(..., indirect_ref)

  • _buildField_build_field

  • _checkKids_check_kids

  • _writeField_write_field

  • _write_field(..., fieldAttributes)_write_field(..., field_attributes)

  • _read_xref_subsections(..., getEntry, ...)_read_xref_subsections(..., get_entry, ...)

PdfWriter 类:

  • writer.getPage(pageNumber)writer.pages[page_number]

  • writer.getNumPages()len(writer.pages)

  • addMetadataadd_metadata

  • addPageadd_page

  • addBlankPageadd_blank_page

  • addAttachment(fname, fdata)add_attachment(filename, data)

  • insertPageinsert_page

  • insertBlankPageinsert_blank_page

  • appendPagesFromReaderappend_pages_from_reader

  • updatePageFormFieldValuesupdate_page_form_field_values

  • cloneReaderDocumentRootclone_reader_document_root

  • cloneDocumentFromReaderclone_document_from_reader

  • getReferenceget_reference

  • getOutlineRootget_outline_root

  • getNamedDestRootget_named_dest_root

  • addBookmarkDestinationadd_bookmark_destination

  • addBookmarkDictadd_bookmark_dict

  • addBookmarkadd_bookmark

  • addNamedDestinationObjectadd_named_destination_object

  • addNamedDestinationadd_named_destination

  • removeLinksremove_links

  • removeImages(ignoreByteStringObject)remove_images(ignore_byte_string_object)

  • removeText(ignoreByteStringObject)remove_text(ignore_byte_string_object)

  • addURIadd_uri

  • addLinkadd_link

  • getPage(pageNumber)get_page(page_number)

  • getPageLayout / setPageLayout / pageLayoutpage_layout attribute

  • getPageMode / setPageMode / pageModepage_mode attribute

  • _addObject_add_object

  • _addPage_add_page

  • _sweepIndirectReferences_sweep_indirect_references

PdfMerger 类

  • __init__ 参数: strict=Truestrict=False (​PdfFileMerger​ 仍然具有旧的默认值)

  • addMetadataadd_metadata

  • addNamedDestinationadd_named_destination

  • setPageLayoutset_page_layout

  • setPageModeset_page_mode

Page 类:

  • artBox / bleedBox / cropBox / mediaBox / trimBoxartbox / bleedbox / cropbox / mediabox / trimbox

    • getWidth, getHeight width / height

    • getLowerLeft_x / getUpperLeft_xleft

    • getUpperRight_x / getLowerRight_xright

    • getLowerLeft_y / getLowerRight_ybottom

    • getUpperRight_y / getUpperLeft_ytop

    • getLowerLeft / setLowerLeftlower_left 属性

    • upperRightupper_right

  • mergePagemerge_page

  • rotateClockwise / rotateCounterClockwiserotate_clockwise

  • _mergeResources_merge_resources

  • _contentStreamRename_content_stream_rename

  • _pushPopGS_push_pop_gs

  • _addTransformationMatrix_add_transformation_matrix

  • _mergePage_merge_page

XmpInformation 类:

  • getElement(..., aboutUri, ...)get_element(..., about_uri, ...)

  • getNodesInNamespace(..., aboutUri, ...)get_nodes_in_namespace(..., aboutUri, ...)

  • _getText_get_text

utils.py:

  • matrixMultiply ➔ `矩阵乘法

  • RC4_encrypt 被移动到安全模块

参数名称

  • PdfWriter.get_page: pageNumberpage_number

  • PyPDF2.filters (所有类): decodeParmsdecode_parms

  • PyPDF2.filters (所有类): decodeStreamDatadecode_stream_data

  • pagenumpage_number

  • PdfMerger.merge: positionpage_number

  • PdfWriter.add_outline_item_destination: destpage_destination

  • PdfWriter.add_named_destination_object: destpage_destination

  • PdfWriter.encrypt: user_pwduser_password

  • PdfWriter.encrypt: owner_pwdowner_password

弃用

一些类/函数在没有替换的情况下被弃用:

  • PyPDF2.utils.ConvertFunctionsToVirtualList

  • PyPDF2.utils.formatWarning

  • PyPDF2.isInt(obj): 使用 instance(obj, int) 替代

  • PyPDF2.u_(s): 直接使用 ​s

  • PyPDF2.chr_(c): 使用 chr(c) 替代

  • PyPDF2.barray(b): 使用 bytearray(b) 替代

  • PyPDF2.isBytes(b): 使用 instance(b, type(bytes())) 替代

  • PyPDF2.xrange_fn: 使用 range 替代

  • PyPDF2.string_type: 使用 str 替代

  • PyPDF2.isString(s): 使用 instance(s, str) 替代

  • PyPDF2._basestring: 使用 str 替代

  • b_(...) 去掉了。您通常应该能够直接使用 bytes 对象,否则您可以复制它