<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0303</schemaVersion>

    <documentType>4</documentType>

    <periodOfReport>2011-02-02</periodOfReport>

    <issuer>
        <issuerCik>0000102212</issuerCik>
        <issuerName>UNIVEST CORP OF PENNSYLVANIA</issuerName>
        <issuerTradingSymbol>UVSP</issuerTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001415199</rptOwnerCik>
            <rptOwnerName>SCHWEITZER JEFFREY M</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>3964 GOSHEN DRIVE</rptOwnerStreet1>
            <rptOwnerStreet2></rptOwnerStreet2>
            <rptOwnerCity>HARLEYSVILLE</rptOwnerCity>
            <rptOwnerState>PA</rptOwnerState>
            <rptOwnerZipCode>19438</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>0</isDirector>
            <isOfficer>1</isOfficer>
            <isTenPercentOwner>0</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle>EVP &amp; CFO</officerTitle>
        </reportingOwnerRelationship>
    </reportingOwner>

    <nonDerivativeTable>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common</value>
            </securityTitle>
            <transactionDate>
                <value>2011-02-02</value>
            </transactionDate>
            <deemedExecutionDate>
                <value>2011-02-02</value>
            </deemedExecutionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>F</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>23</value>
                    <footnoteId id="F1"/>
                </transactionShares>
                <transactionPricePerShare>
                    <value>17.57</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>12596.9961</value>
                    <footnoteId id="F2"/>
                    <footnoteId id="F3"/>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value></value>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeHolding>
            <securityTitle>
                <value>Common</value>
            </securityTitle>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>12596.9961</value>
                    <footnoteId id="F2"/>
                    <footnoteId id="F3"/>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
                <natureOfOwnership>
                    <value></value>
                </natureOfOwnership>
            </ownershipNature>
        </nonDerivativeHolding>
    </nonDerivativeTable>

    <footnotes>
        <footnote id="F1">VESTED SHARES USED TO PAY TAXES</footnote>
        <footnote id="F2">DOES INCLUDE 707.9961 SHARES ACQUIRED ON OR AFTER AUGUST 15, 1996 THROUGH THE DIVIDEND REINVESTMENT PLAN AND EMPLOYEE STOCK PURCHASE PLAN.</footnote>
        <footnote id="F3">DOES INCLUDE 9,905 SHARES OF RESTRICTED STOCK.</footnote>
    </footnotes>

    <remarks></remarks>

    <ownerSignature>
        <signatureName>Jeffrey M. Schweitzer</signatureName>
        <signatureDate>2011-02-03</signatureDate>
    </ownerSignature>
</ownershipDocument>
