QPDF::parse(char const* password)
{
    if (password)
    {
	this->m->encp->provided_password = password;
    }

    // Find the header anywhere in the first 1024 bytes of the file.
    PatternFinder hf(*this, &QPDF::findHeader);
    if (! this->m->file->findFirst("%PDF-", 0, 1024, hf))
    {
	QTC::TC("qpdf", "QPDF not a pdf file");
	warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
                     "", 0, "can't find PDF header"));
        // QPDFWriter writes files that usually require at least
        // version 1.2 for /FlateDecode
        this->m->pdf_version = "1.2";
    }
    if (atof(this->m->pdf_version.c_str()) < 1.2)
    {
        this->m->tokenizer.allowPoundAnywhereInName();
    }

    // PDF spec says %%EOF must be found within the last 1024 bytes of
    // the file.  We add an extra 30 characters to leave room for the
    // startxref stuff.
    this->m->file->seek(0, SEEK_END);
    qpdf_offset_t end_offset = this->m->file->tell();
    qpdf_offset_t start_offset = (end_offset > 1054 ? end_offset - 1054 : 0);
    PatternFinder sf(*this, &QPDF::findStartxref);
    qpdf_offset_t xref_offset = 0;
    if (this->m->file->findLast("startxref", start_offset, 0, sf))
    {
        xref_offset = QUtil::string_to_ll(
            readToken(this->m->file).getValue().c_str());
    }

    try
    {
	if (xref_offset == 0)
	{
	    QTC::TC("qpdf", "QPDF can't find startxref");
	    throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
			  "can't find startxref");
	}
	read_xref(xref_offset);
    }
    catch (QPDFExc& e)
    {
	if (this->m->attempt_recovery)
	{
	    reconstruct_xref(e);
	    QTC::TC("qpdf", "QPDF reconstructed xref table");
	}
	else
	{
	    throw e;
	}
    }

    initializeEncryption();
    findAttachmentStreams();
}
QPDF::parse(char const* password)
{
    if (password)
    {
	this->m->encp->provided_password = password;
    }

     
    PatternFinder hf(*this, &QPDF::findHeader);
    if (! this->m->file->findFirst("%PDF-", 0, 1024, hf))
    {
	QTC::TC("qpdf", "QPDF not a pdf file");
	warn(QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(),
                     "", 0, "can't find PDF header"));
         
         
        this->m->pdf_version = "1.2";
    }
    if (atof(this->m->pdf_version.c_str()) < 1.2)
    {
        this->m->tokenizer.allowPoundAnywhereInName();
    }

     
     
     
    this->m->file->seek(0, SEEK_END);
    qpdf_offset_t end_offset = this->m->file->tell();
    qpdf_offset_t start_offset = (end_offset > 1054 ? end_offset - 1054 : 0);
    PatternFinder sf(*this, &QPDF::findStartxref);
    qpdf_offset_t xref_offset = 0;
    if (this->m->file->findLast("startxref", start_offset, 0, sf))
    {
        xref_offset = QUtil::string_to_ll(
            readToken(this->m->file).getValue().c_str());
    }

    try
    {
	if (xref_offset == 0)
	{
	    QTC::TC("qpdf", "QPDF can't find startxref");
	    throw QPDFExc(qpdf_e_damaged_pdf, this->m->file->getName(), "", 0,
			  "can't find startxref");
	}
	read_xref(xref_offset);
    }
    catch (QPDFExc& e)
    {
	if (this->m->attempt_recovery)
	{
	    reconstruct_xref(e);
	    QTC::TC("qpdf", "QPDF reconstructed xref table");
	}
	else
	{
	    throw e;
	}
    }

    initializeEncryption();
    findAttachmentStreams();
}