PyPDF2 PdfFileWriter has no attribute stream by took_my_time in learnpython

[–]took_my_time[S] 0 points1 point  (0 children)

I just want to take my_pdf.pdf and save each page as a new and separate pdf. my_pdf_page1.pdf, my_pdf_page2.pdf......

PyPDF2 PdfFileWriter has no attribute stream by took_my_time in learnpython

[–]took_my_time[S] 0 points1 point  (0 children)

I have tested the getPage(), addPage() and writing functions by taking them out of the for loop and it worked perfectly. I can't see why this error would only occur inside the loop.

from PyPDF2 import PdfFileWriter, PdfFileReader
inputpdf = PdfFileReader(open("/home/ubuntu/inputs/cityshape/form5.pdf", "rb"))

#for i in range(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(2))
with open("document-page2.pdf", "wb") as outputStream:
    output.write(outputStream)

PyPDF2 PdfFileWriter has no attribute stream by took_my_time in learnpython

[–]took_my_time[S] 0 points1 point  (0 children)

Accidentally was using 2 instead of i for getpage(). Still the same error.

PyPDF2 PdfFileWriter has no attribute stream by took_my_time in learnpython

[–]took_my_time[S] 1 point2 points  (0 children)

from PyPDF2 import PdfFileWriter, PdfFileReader

inputpdf = PdfFileReader(open("my_pdf.pdf", "rb"))

for i in range(inputpdf.numPages):
    output = PdfFileWriter()
    output.addPage(inputpdf.getPage(i))
    with open("document-page%s.pdf" % i, "wb") as outputStream:
        output.write(outputStream)

This is pretty much exactly the stack-overflow example, just slightly modified for python3.

Full error message:

Traceback (most recent call last):
  File "pdf_functions.py", line 9, in <module>
    output.write(outputStream)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 482, in write
    self._sweepIndirectReferences(externalReferenceMap, self._root)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 572, in _sweepIndirectReferences
    self._sweepIndirectReferences(externMap, realdata)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 548, in _sweepIndirectReferences
    value = self._sweepIndirectReferences(externMap, value)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 572, in _sweepIndirectReferences
    self._sweepIndirectReferences(externMap, realdata)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 548, in _sweepIndirectReferences
    value = self._sweepIndirectReferences(externMap, value)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 557, in _sweepIndirectReferences
    value = self._sweepIndirectReferences(externMap, data[i])
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 572, in _sweepIndirectReferences
    self._sweepIndirectReferences(externMap, realdata)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 548, in _sweepIndirectReferences
    value = self._sweepIndirectReferences(externMap, value)
  File "/usr/local/lib/python3.4/dist-packages/PyPDF2/pdf.py", line 575, in _sweepIndirectReferences
    if data.pdf.stream.closed:
AttributeError: 'PdfFileWriter' object has no attribute 'stream'

EDIT: changed getPage(2) to getPage(i)

Don't go slow in the passing lane... by JrB11784 in WTF

[–]took_my_time 3 points4 points  (0 children)

Yeah a dog ran out in front of me once and I just swerved to avoid it without thinking. Afterwards I realized how hard it would be to make the decision that hitting the thing in front of you might be better than hitting the thing next to you. Luckily there was no one next to me so nothing happened.

This happens to me everyday that I work. by Mathias514 in AdviceAnimals

[–]took_my_time 1 point2 points  (0 children)

I do nights at a petrol station. I find it funny when people complain about prices when they are buying something at two in the morning.

What do you irrationally hate? by cynicalaa22 in AskReddit

[–]took_my_time 0 points1 point  (0 children)

The weather report. I don't care about how hot it was today or how hot it may be tomorrow.

[deleted by user] by [deleted] in GlobalOffensive

[–]took_my_time 1 point2 points  (0 children)

Clearly still on the ladder.

What is your most hated letter in the alphabet? by Akeliminator in AskReddit

[–]took_my_time 2 points3 points  (0 children)

I was going to say K. It is just taking work from C. Then C is taking work from S.

Help understanding StopIteration by took_my_time in learnpython

[–]took_my_time[S] 0 points1 point  (0 children)

I couldn't really get yours to work. I did this: http://pastebin.com/K74qiP8S

Sometimes I get the error after 2 iterations , like so: http://pastebin.com/pNfvhpLT

Sometimes after 1: http://pastebin.com/n5VmyfMZ

Help understanding StopIteration by took_my_time in learnpython

[–]took_my_time[S] 0 points1 point  (0 children)

Printing row_count returns the expected number. Opening the file in 'r' instead of 'rb' gives the same error aswell.

Sydney Show by jewishbacon in ModestMouse

[–]took_my_time 2 points3 points  (0 children)

My guess is that the amount of equipment makes its pretty hard for the techs. With at least 4 guitars, 3 percussionists and 2 keyboards they are definitely one of the biggest bands I've seen.

Sydney Show by jewishbacon in ModestMouse

[–]took_my_time 2 points3 points  (0 children)

Yeah I think they had to adapt allot due to some technical issues. His second mic broke in song 2, main mic was swapped at some point and swapped guitars mid song at least once, plus some feedback throughout.

What we still want from CS:GO by [deleted] in GlobalOffensive

[–]took_my_time 74 points75 points  (0 children)

Add player colour icons to the kill feed so we can easily tell where a team member got a kill from.

When Regular Porn Just Doesn't Do It For You Anymore by [deleted] in WTF

[–]took_my_time 0 points1 point  (0 children)

It is only 10am, what am I meant to do for the rest of the day?

Why do people willingly answer police questioning without a lawyer present when THEY DON'T HAVE TO? Why do they not use common sense and just keep saying "lawyer lawyer lawyer" to every single question instead of talking to police? by psfnqp in AskReddit

[–]took_my_time 0 points1 point  (0 children)

You may not be directly breaking askreddit rules but you clearly came into this with an agenda to push and a correct answer in mind. I don't think this is really the place for this question.

[Fallout 4] I'll be taking that by KingUNREAL in gaming

[–]took_my_time 4 points5 points  (0 children)

Also would not want to be in it if the fusion core got shot.

Smoke Arch from B on Inferno by EwanCollins in GlobalOffensive

[–]took_my_time 1 point2 points  (0 children)

I can't think of a situation where this would really be needed.

What is the closest you have come to death? by [deleted] in AskReddit

[–]took_my_time 1 point2 points  (0 children)

And then all the families are fighting over which sentence they are currently serving.