Exporting test results to PDF tables
Some quick remarks:


pid, dateofvisit, stamp, type are all properties and thus should follow Microsoft's naming guidelines. Moreover "pid" is fairly meaningless, why not call this "PetId" as well?
testTypes does not convey its actual contents.
Using an int to indicate a type is meaningless. I don't know what a test of type "1" is, or a "2". You should translate this into an enum with meaningful values.
WRT // columns are the number of tests in every TestTable: why do you need this? Can't you just count the entries in the property Tests?
Why is GetTable(Test test, ref TestTable table, int index) a public method? I doubt this is re-used elsewhere. Please apply the correct access modifier to a method, class, property, field etc.




I find your logic hard to understand. I've tried to rewrite it, based on what I think is happening, and this is what I came up with:

    public IEnumerable&lt;TestTable&gt; TestHistoryItems()
    {
        IEnumerable&lt;Test&gt; tests = // get data

        var testTables = new List&lt;TestTable&gt;();

        foreach (var testType in new int[] { 3, 4, 5, 6, 7, 8, 9, 10, 16 })
        {
            var relevantTests = tests.Where(x =&gt; x.Type == testType).ToList();

            if (!relevantTests.Any())
            {
                continue;
            }

            testTables.Add(GetTestTable(relevantTests));
        }

        return testTables;
    }

    private TestTable GetTestTable(IReadOnlyCollection&lt;Test&gt; tests)
    {
        var sampleTest = tests.First();
        return new TestTable
        {
            TestName = sampleTest.TestTypeName,
            Type = sampleTest.Type,
            Rows = sampleTest.TestDatas.Count,
            Tests = tests
        };
    }


You could even reduce the first method even more:

    public IEnumerable&lt;TestTable&gt; TestHistoryItems()
    {
        IEnumerable&lt;Test&gt; tests = // get data

        return new[] { 3, 4, 5, 6, 7, 8, 9, 10, 16 }
            .Select(testType =&gt; tests.Where(x =&gt; x.Type == testType).ToList())
            .Where(relevantTests =&gt; relevantTests.Any())
            .Select(GetTestTable)
            .ToList();
    }


To me, this looks a lot clearer: I see there's a list of test types you filter on, and based on that you make a List of TestTables for each type that has actual tests.

Again: I'm not 100% sure this is what you're doing, and that's because of the convoluted way your code works. And that is a major problem: good code can almost be "read" as a story. When I need to spend time trying to figure out that index is actually a test type that you've re-purposed, etc., that's a waste of time and energy.