pankajr141 / pdf2jpg Goto Github PK
View Code? Open in Web Editor NEWUtility to convert PDF into JPG files
Utility to convert PDF into JPG files
在调用java命令时出现如下错误:
java.io.IOException: XREF for 2748:0 points to wrong object: 2749:0 at offset 1243393#################################
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.pdfbox.io.ScratchFileBuffer.addPage(ScratchFileBuffer.java:132)
at org.apache.pdfbox.io.ScratchFileBuffer.ensureAvailableBytesInPage(ScratchFileBuffer.java:184)
at org.apache.pdfbox.io.ScratchFileBuffer.write(ScratchFileBuffer.java:236)
at org.apache.pdfbox.io.ScratchFileBuffer.write(ScratchFileBuffer.java:220)
at org.apache.pdfbox.io.RandomAccessOutputStream.write(RandomAccessOutputStream.java:52)
at org.apache.pdfbox.filter.DCTFilter.decode(DCTFilter.java:147)
at org.apache.pdfbox.cos.COSInputStream.create(COSInputStream.java:69)
at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:162)
at org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:235)
at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.(PDImageXObject.java:125)
at org.apache.pdfbox.pdmodel.graphics.PDXObject.createXObject(PDXObject.java:70)
at org.apache.pdfbox.pdmodel.PDResources.getXObject(PDResources.java:409)
at org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:53)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:838)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:495)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:469)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:150)
at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:206)
at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:145)
at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:94)
at hd.pdf2jpg.PDF2JPGConverter.convertMulti(PDF2JPGConverter.java:76)
at hd.pdf2jpg.App.main(App.java:102)
maj 03, 2020 9:43:58 PM org.apache.pdfbox.cos.COSDocument finalize
WARNING: Warning: You did not close a PDF Document
Can this be solved somehow?
I noticed that script is not working if it is on a path that include spaces (C:\Users\user\test pdf2jpg\test.py). I am using windows.
I fixed this inside library by adding quotas to jarPath right after it is defined inside convert_pdf2jpg function.
jarPath = f'"{jarPath}"'
code like this:result = pdf2jpg.convert_pdf2jpg(inputpath, outputpath, pages="ALL")
exception is :AttributeError: 'function' object has no attribute 'convert_pdf2jpg'
Anyone try out on MAC OS? I keep getting the no such file or directory error. Not sure what is the correct path format on MAC OS. Below is the error message
[Errno 2] No such file or directory: 'java -jar /Users/vincent/miniconda3/envs/MM_tuition/lib/python3.6/site-packages/pdf2jpg/pdf2jpg.jar -i "/Users/vincent/Documents/AUS/Australian National University/test.pdf" -o "/Users/vincent/Documents/AUS/Australian National University" -d 300 -p ALL': 'java -jar
when I run the code, it has an error: no module named command. then I replace command to subprocess,it worked
Hi @pankajr141 ,
I am currently coming across an unusual error when running your package on AWS Lambda. For 99.9% of the time it successfully converts pdfs to jpg, which is amazing! However for the odd one or two occasions it returns a limited error message:
Command '['java', '-jar', '/opt/python/lib/python3.6/site-packages/pdf2jpg/pdf2jpg.jar', '-i', '/tmp/my_pdf.pdf', '-o', '/tmp/', '-d', '300', '-p', 'ALL']' returned non-zero exit status 1.
Would you know why this is happening? Any help around this would be much appreciated. Sadly I can't share the pdf as it is linked to my company.
The _convert_pdf2jpg_single() function takes the output path and then appends the name of the input file to create a new directory, but that results in directory file paths that have periods in them and then puts files in there with that garbage. An example file at the end of the process: "outputpath/filename.pdf_dir/01_filename.jpeg"
I would suggest simply removing the creation of the new directory, trust that the user has put enough thought into where they want their files to go when they specify a outputpath.
Executing the below:
from pdf2jpg import pdf2jpg
inputpath = r'D:\sample.pdf'
outputpath = r'D:\image.jpg'
result = pdf2jpg.convert_pdf2jpg(inputpath, outputpath, dpi=300, pages="ALL")
print(result)
Error I get:
[WinError 2] The system cannot find the file specified
False
My code is:
`def pdf2jpg():
inputpath = "File.pdf"
outputpath = myfile #Don't worry about it, i put there path
# to convert all pages
result = pdf2jpg.convert_pdf2jpg(inputpath, outputpath, pages="ALL")
print(result)
if name == "main":
pdf2jpg()
`
Then i got error as:
AttributeError: 'function' object has no attribute 'convert_pdf2jpg'
I use this module on centos 7, but get an error that "expected str, bytes or os.PathLike object, not int", what can I do to run it on centos 7?
Executing:
from pdf2jpg import pdf2jpg
pdf = r'C:\pdf\г. Советский Картопья вода.pdf'
outputpath = r'C:\pdf\images'
results = pdf2jpg.convert_pdf2jpg(pdf, outputpath, pages="ALL")
print('results=', results)
Gives error:
'utf-8' codec can't decode byte 0xe3 in position 65: invalid continuation byte
results= False
please commit license file
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.