我想把一个给定的PDF的页面分割成单独的PDF。
下面是我写的代码,但在这里,当使用open()和.write()函数保存文件时,我得到了错误: AssertionError
from PyPDF2 import PdfFileReader, PdfFileWriter
pdf = PdfFileReader("input.pdf") # this is the source pdf
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(p
我在Python中合并了许多PDF文件,并得到了错误“errno 2 nno such file or directory”,尽管该文件是存在的。
我试图显示PDF文件,只是为了显示PDF文件的存在。
import os
from PyPDF2 import PdfFileMerger
merger = PdfFileMerger()
source_dir = os.getcwd() + '/Combined PDF'
for items in os.listdir(source_dir):
if items.endswith('.pdf'):
是否可以在Django视图中显示多个PDF文件,而不是只显示一个?
我当前的视图只显示一个
class PdfView(View):
def get(self, request, *args, **kwargs):
for pdf in pdfs:
with open('/path/to/pdf/file/' + pdf.title + '.pdf', 'r') as pdf:
response = HttpResponse(pdf.read(), content
如何在Python3中将HTML转换为PDF?Xhtml2pdf不工作在Python3中,got错误:
import xhtml2pdf.pisa as pisa Traceback (most recent call last): File "", line 1, in File "/home/hound/test/python/test\_env/lib/python3.4/site-packages/xhtml2pdf/**init**.py", line 41, in
我一直在用Python创建一个程序,将2个pdf文件合并到一个文件中。这是代码:-
import os
from PyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.endswith('pdf'):
merger.append(item)
merger.write('completed_file.pdf')
merger.close()
在运
我有以下脚本,它用python-script转换pdf-文件,我的python-脚本有三个输入:pperation-键输入-文件输出-文件。操作键的值可以为null,1,2。
#!/bin/bash
for f in *.pdf
do
outputdir="`pwd`/${f%.pdf}_out.pdf"
inputdir="`pwd`/$f"
python <myscript> "null" $inputdir $outputdir
done
在终端中,python使用以下输入,但在shell脚本中不工作:
我试图给pypdf一些要合并的pdf,但它抛出了一个coercing to Unicode错误。我的代码是
from PyPDF2 import PdfFileMerger, PdfFileReader
import pdfcrowd
from django.http import HttpResponse
def generate_pdf(request):
list_of_pages = ["http://127.0.0.1:8000/page"+x+"/" for x in list("1234567")]
pdfs =
我一直在创建一个使用PyPdf2合并多个pdf文件的Python程序.
这是代码
import os
from PyPDF2 import PdfFileMerger
source_dir = os.getcwd()
merger = PdfFileMerger()
for item in os.listdir(source_dir):
if item.endswith('pdf'):
merger.append(item)
merger.write('completed_file.pdf')
merger.close()
在运行
我正在尝试从PHP运行一个python脚本。python脚本从文本文件中读取内容,并相应地创建PDF。当我从终端运行Python脚本时,它运行得非常完美,并且得到了所需的PDF。但是,当我试图从PHP运行python脚本时,它会给出以下错误:
Traceback (most recent call last): File "/home/amogh/server/test.py", line 3, in from fpdf import FPDF ImportError: No module named fpdf
PHP代码:
<?php
$output = shell_
我想删除空的文件。
import os
book_list = ['Automate the Boring Stuff with Python.pdf',
'OReilly.Think.Python.2nd.Edition.2015.12.pdf',
'Apress-Magnus_Lie_Hetland-python_algorithms.pdf',
'Python for Data Analysis - 2012.pdf']
for book in book_list:
if os.path.getsize(boo
我想做一个将PDF转换成PNG的Python程序,但当我运行代码时,由于某种原因,它显示了一个错误。 下面是我的代码: from pdf2image import convert_from_path
from tkinter import filedialog
filename = filedialog.askopenfilename()
images = convert_from_path(filename)
for i in range (len(images)):
images[i].save("page" + str(i) + ".png"
首先,我使用的是Python3.5.1 (32位版本),我编写了以下程序,使用PyPDF2和reportlab在我的pdf文件的所有页面上添加页码:
#import modules
from os import listdir
from PyPDF2 import PdfFileWriter, PdfFileReader
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
#initial values of variable declarations
PDFlist=[]
X
我尝试在Google Cloud Functions上将PDF转换为JPEG。我使用了Python模块pdf2image。但是我不知道如何解决云函数上的错误No such file or directory: 'pdfinfo'和"Unable to get page count. Is poppler installed and in PATH?。 错误代码与this question非常相似。pdf2image是"pdftoppm“和"pdftocairo”的包装器。但是如何在google cloud function上安装poppler包,并将其