In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how python changes the width and height of pictures in pdf format". In daily operation, I believe many people have doubts about how to change the width and height of pictures in python format. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "how to change the width and height of pictures in pdf format by python". Next, please follow the editor to study!
Chloroplast genome articles usually use OGDRAW to draw circles. I usually save them in pdf format, adjust some details, and then use Adobe Acrobat Pro to save pictures in other formats. At this time, if you choose 300 pixels per centimeter in the setting, he will prompt that the image is too wide to output. At this time, I naturally think of whether I can adjust the length and width of the picture in pdf format.
Search python to change the width and height of pdf to find https://stackoverflow.com/questions/6536552/resize-pdf-pages-in-python
If you want to change the width and height of pdf, you must first know the width and height of pdf
Use the Adobe Acrobat Pro software to view the length and width of the picture through the file-attribute (in centimeters)
The PyPDF2 module in python can also obtain length and width information.
The code is
Import PyPDF2
Pdf1 = PyPDF2.PdfFileReader ("01.pdf")
Pdf1.getPage (0). MediaBox
The result returned is
RectangleObject ([0,0,457,468])
The last two numbers are wide and high The format is ['0mm,' 0mm, width, height]
The unit of this number is pt. One pt equals 72 inch and one inch equals 2.54cm.
Seeing this, I suddenly figured out a truth. When I use Adobe Acrobat Pro software to save as a picture, there is an option of 118.11 pixels per centimeter, and I have always wondered why there is such a zero and integral. It turns out that 118.11 * 2.54 equals 299.9994 or so, so this option is what we often call 300 dpi (dot per inch).
The code used to scale pdf
Import PyPDF2
Pdf = PyPDF2.PdfFileReader ("001_Figure1.pdf")
P0 = pdf.getPage (0)
P0.scaleBy (0.5)
Writer = PyPDF2.PdfFileWriter ()
Writer.addPage (p0)
With open ("01.pdf", 'wb+') as f:
Writer.write (f)
The width and height of the 001_Figure1.pdf pdf file is 32.240 * 33.016 cm scaleBy (0.5) and then becomes 16.120 * 16.508.
If you save as at this time, there will be no hint that the image is too wide to output.
At this point, the study on "how python changes the width and height of pictures in pdf format" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.